使用KiCad设计 RP2040 电路板(第一版

Design an RP2040 board

with KiCad, 1st Edition

使用 KiCad 设计 RP2040 板

Design an RP2040 board with KiCad

作者:乔·欣克利夫和本·埃弗拉德

by Jo Hinchliffe and Ben Everard

ISBN: 978-1-916868-13-7

ISBN: 978-1-916868-13-7

版权所有 © 2024 Jo Hinchliffe 和 Ben Everard

Copyright © 2024 Jo Hinchliffe and Ben Everard

英国印刷

Printed in the United Kingdom

由 Raspberry Pi Ltd. 出版,地址:194 Science Park, Cambridge, CB4 0AB

Published by Raspberry Pi Ltd., 194 Science Park, Cambridge, CB4 0AB

编辑:本·埃弗拉德、布莱恩·杰普森

Editors: Ben Everard, Brian Jepson

室内设计师:萨拉·帕罗迪

Interior Designer: Sara Parodi

制作:内莉·麦克凯森

Production: Nellie McKesson

摄影师:布莱恩·奥哈洛兰

Photographer: Brian O’Halloran

插画师:萨姆·奥尔德

Illustrator: Sam Alder

图形编辑:娜塔莉·特纳

Graphics Editor: Natalie Turner

出版总监:布莱恩·杰普森

Publishing Director: Brian Jepson

设计主管:杰克·威利斯

Head of Design: Jack Willis

首席执行官:埃本·厄普顿

CEO: Eben Upton

2024年9月:第一版

September 2024: First Edition

出版商和撰稿人对本书中提及或宣传的商品、产品或服务的任何遗漏或错误概不负责。除非另有说明,本书内容采用知识共享署名-非商业性使用-相同方式共享 3.0 未本地化版本 (CC BY-NC-SA 3.0) 许可协议。

The publisher, and contributors accept no responsibility in respect of any omissions or errors relating to goods, products or services referred to or advertised in this book. Except where otherwise noted, the content of this book is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported (CC BY-NC-SA 3.0)

欢迎

Welcome

KiCad 是一款出色的免费开源软件,任何人只要投入一些时间和精力,就能制作出高质量的 PCB 设计。将这款优秀的软件与众多 PCB 制造公司,甚至是 PCBA 服务(这些公司可以帮你制造和组装 PCB 设计)结合起来,现在正是进入 PCB 制造领域的最佳时机。

KiCad is an amazing piece of free and open-source software that allows anyone, with some time and effort, to make high-quality PCB designs. Couple this amazing software with numerous PCB fabrication companies and even PCBA services — companies that will make and assemble your PCB designs — and there’s never been a better time to get into this aspect of making.

本书以RP2040微控制器芯片(树莓派Pico的核心芯片)为基础,对PCB设计进行了浅显易懂的介绍。您将学习在KiCad中创建原理图和PCB设计的基础知识,并了解如何使用您自己创建(或从其他来源获取)的元件封装等素材。您还将了解如何将PCB设计进行生产,以及如何安装表面贴装元件。

This book provides a gentle introduction to PCB design using the RP2040 microcontroller chip (the same chip that's at the heart of Raspberry Pi Pico). You'll learn the basics of creating schematics and PCB designs in KiCad and learn how to work with artifacts such as component footprints that you create yourself (or get from another source). You’ll find out how to get a PCB design manufactured — and populated with surface-mount components.

你还将学习如何让你的PCB板从普通电路板中脱颖而出,例如添加你自己的设计图稿、将PCB板用作结构组件,或者使用3D打印部件来增强你的设计。你还将了解各种可用的PCB材料,包括柔性PCB板,并学习与制造商合作的技巧和诀窍,以确保你的电路板最终能够达到预期效果。

You’ll also learn how to make your PCBs stand out from more generic boards, whether by adding your own artwork, using the PCB as a structural component, or augmenting your design with 3D-printed parts. You’ll also find out about the difference PCB materials available, including flexible PCBs, and learn tips and tricks for working with fabricators to make sure your boards come out as intended.

您可以在本书的 GitHub 代码库hsmag.cc/kicad_book_files中找到本书的示例代码、勘误表和其他资源。如果您发现本书中存在任何错误或疏漏,请在该 GitHub 代码库中提交 issue 告知我们。

You can find this book’s example code, errata, and other resources in its GitHub repository at hsmag.cc/kicad_book_files. If you’ve found what you believe is a mistake or error in the book, please let us know by opening an issue in that GitHub repository.

关于作者

About the authors

Jo Hinchliffe(又名 Concretedog)是个爱捣鼓各种东西的人,对DIY太空相关的一切都充满热情。他喜欢设计和自制模型火箭和高功率火箭,并将设计和组件开源发布。他的工具棚里还堆满了车床、铣床和数控机床!

Jo Hinchliffe (AKA Concretedog) is a constant tinkerer and is passionate about all things DIY space. He loves designing and scratch-building both model and high-power rockets and releases the designs and components as open source. He also has a shed full of lathes and milling machines and CNC kit!

本·埃弗拉德热衷于艺术与科技的交融。他对光有着浓厚的兴趣,制作印刷电路板的主要目的是为了探索更多将LED灯集成到各种物品中的方法。他和妻子、两个女儿以及一大群宠物住在布里斯托尔的一栋房子里。

Ben Everard enjoys working at the intersection of art and technology. He has a particular interest in light and his primary reason for making PCBs is to find more ways of adding LEDs to things. He lives in a house in Bristol with his wife, two daughters and too many animals.

版权页

Colophon

树莓派价格实惠,可以用来做一些有用的事情,或者做一些有趣的事情。

Raspberry Pi is an affordable way to do something useful, or to do something fun.

自树莓派项目启动以来,我们始终秉持着普及技术、让更多人能够使用工具的理念。通过将通用计算的成本降至 5 美元以下,我们让任何人都能参与到以往需要巨额资金投入的项目中。如今,随着准入门槛的降低,我们看到树莓派计算机的应用范围极其广泛,从互动式博物馆展览、学校到国家邮政分拣中心和政府呼叫中心,无处不在。世界各地的家庭作坊式企业也得以发展壮大并取得成功,这在过去是难以想象的,因为在笔记本电脑和台式机上集成技术意味着要花费巨资。

Democratising technology — providing access to tools — has been our motivation since the Raspberry Pi project began. By driving down the cost of general-purpose computing to below $5, we’ve opened up the ability for anybody to use computers in projects that used to require prohibitive amounts of capital. Today, with barriers to entry being removed, we see Raspberry Pi computers being used everywhere from interactive museum exhibits and schools to national postal sorting offices and government call centres. Kitchen table businesses all over the world have been able to scale and find success in a way that just wasn’t possible in a world where integrating technology meant spending large sums on laptops and PCs.

树莓派消除了各个年龄段人群使用计算机的高昂门槛:孩子们可以从以前无法接触到的计算机教育中受益,而许多成年人也长期以来因为价格昂贵而无法将计算机用于企业、娱乐和创作。

Raspberry Pi removes the high entry cost to computing for people across all demographics: while children can benefit from a computing education that previously wasn’t open to them, many adults have also historically been priced out of using computers for enterprise, entertainment, and creativity.

树莓派消除了这些障碍。

Raspberry Pi eliminates those barriers.

树莓派出版社

Raspberry Pi Press

store.rpipress.cc

store.rpipress.cc

Raspberry Pi Press 是您进行计算机、游戏和动手实践的必备书架。我们是 Raspberry Pi Ltd. 的出版品牌。从组装 PC 到制作机箱,我们丰富的书籍和杂志将帮助您发现兴趣所在,学习新技能,并创造出令人惊叹的作品。

Raspberry Pi Press is your essential bookshelf for computing, gaming, and hands-on making. We are the publishing imprint of Raspberry Pi Ltd. From building a PC to building a cabinet, discover your passion, learn new skills, and make awesome stuff with our extensive range of books and magazines.

MagPi

The MagPi

magpi.raspberrypi.com

magpi.raspberrypi.com

MagPi是树莓派官方杂志。它面向树莓派社区,内容涵盖树莓派主题项目、计算机和电子教程、操作指南以及最新的社区新闻和活动。

The MagPi is the official Raspberry Pi magazine. Written for the Raspberry Pi community, it is packed with Pi-themed projects, computing and electronics tutorials, how-to guides, and the latest community news and events.

第一章

Chapter 1

使用原理图

Working with schematics

在设计PCB之前,必须先设计电路。

Before you design the PCB, you must design the circuit

PCB设计学习曲线陡峭。鉴于此,本书将以一个简易教程作为开篇。在前两章中,你将完成PCB设计,直至最终投入生产。为了降低学习难度,我们会简化一些步骤。别担心,我们会解释哪些步骤被简化了,并且在你掌握基础知识后,后续章节将教授正确的方法。

PCB design has a steep learning curve. With that in mind, we want to start this book with a hack. In the first two chapters, you’ll create a PCB design to the point of getting it manufactured. To ease up on the learning curve, you will cut some corners. Don’t worry, we’ll explain what corner were cut, and you’ll learn the correct approach in subsequent chapters, once you have the basics down.

图 1-1:本章你将开始设计的电路板

首先从kicad.org下载并安装 KiCad——截至撰写本文时,稳定版本为 8。KiCad 可在多种操作系统上运行——Windows、macOS 和许多 Linux 发行版。

Start by downloading and installing KiCad from kicad.org — at the time of writing, the stable version was 8. KiCad is available across a wide range of operating systems – Windows, macOS, and lots of Linux distributions.

安装完成后,点击蓝色的 KiCad 主 图标 即可打开主应用程序。您应该会看到类似图 1-2 的界面。KiCad 实际上并非一个单独的应用程序,而更像是一套协同工作的应用程序。虽然您可以从这里直接进入任何应用程序,但 KiCad 最常见的工作流程是先在原理图编辑器中创建原理图,然后再转到 PCB 编辑器进行 PCB 的物理布局。

With it installed, click on the main blue Ki KiCad icon to open the main application. You should see a screen that looks like Figure 1-2. KiCad isn’t really a single application, it’s more like a suite of applications that work together. While you can jump into any application from here, the most common workflow for KiCad is to first work in the Schematic Editor and after creating a schematic, move to the PCB Editor to lay out the PCB physically.

你将为树莓派 Pico 制作一个扩展板。它将是一个功能不多的原型板或“简易”板。所有 Pico 的引脚都将引出到直插焊盘上,板上会有一个电源指示灯和一个复位按钮。之后,板上的剩余区域将布置一个简单的直插焊盘网格(有时称为原型区域),以便你将实验设备连接到板上。虽然比较简陋,但它可以帮助你学习一些 KiCad 的基础知识。

You’ll create an add-on board for the Raspberry Pi Pico. It’s going to be a prototyping or ‘kludge’ board with not too many features on it. It’s going to have all the Pico pins broken out to through-hole pads, it will have a power-indicating LED, and it will have a reset button. After this, any spare area on the board will have a grid of simple through-hole pads (sometimes called a prototyping area) on it to allow you to connect experiments to the board. It’s a bit rudimentary but will help you learn some KiCad basics.

图 1-2: KiCad 的首页,其中列出了构成 KiCad 套件的不同应用程序。

首先,您应该创建一个新项目。点击“文件”>“新建项目”来创建一个新项目。建议将项目放在单独的文件夹中,因为每个 KiCad 项目都会生成大约五个项目文件,以及一个用于自动生成项目备份文件的文件夹。

Your first action should be to set up a new project. Click File > New Project to create a new project. It’s worth putting projects into their own folder as each KiCad project generates around five project files and a folder in which it automatically generates some project backup files.

创建新项目后,点击顶部图标打开原理图编辑器应用程序。首次运行原理图编辑器时,KiCad 会提示您配置全局符号库表。选择“复制默认全局符号库表(推荐)”,然后点击“确定”。

Once the new project is created, open the Schematic Editor application by clicking the top icon. The first time you run the Schematic Editor, KiCad will ask you to configure your global symbol library table. Choose Copy default global symbol library table (recommended) and click OK.

小贴士

在 KiCad 中,将鼠标悬停在任何工具图标上,即可查看该工具的描述。本书将使用这些工具提示来描述各种工具图标。

If you hover over any tool icon in KiCad, you get a description of the tool. We’ll use these tooltips to describe tool icons throughout this book.

你会看到一张空白页面,可以用来绘制原理图(图 1-3)。在右下角,你会看到一小块文本框,其中包含各种字段,例如图纸名称、原理图版本号等等。点击此区域的任意位置,然后按E键,即可打开“页面设置”对话框。你可以在此对话框中编辑,添加任何你想要的文本信息或注释,还可以更改页面尺寸(默认为 A4)、方向等等。尝试在“页面设置”窗口中输入文本,看看文本在原理图中的显示位置。

You’ll see a blank page ready for you to draw a schematic (Figure 1-3). In the lower right-hand corner, you will see a small collection of text boxes which include various fields for the name of the sheet, the revision number of the schematic, and more. If you click somewhere on this section and then press the E key, the Page Settings dialogue will appear. You can edit this to add any text details or comments you want to add to this section, but you can also change the page dimensions (it defaults to A4), the orientation, and more. Experiment inserting text into the Page Settings window to see where the text appears on the schematic.

图 1-3:一张空白原理图纸,带有用于各种原理图标签和

版本编号的文本框

页面设置完成后,您现在可以开始向原理图添加原理图符号了。制作 Pico 扩展板最正确的方法是在原理图中放置一个 Pico 并将所有组件连接到它,但您将使用一种更简单的变通方法。目标扩展板的主要目的是让您能够焊接多排排针插座,以便将其连接到 Pico 的引脚上。同时,您仍然需要能够焊接这些引脚,因此需要将每排引脚引出到另一组焊盘上。

With your page set up, you can now begin to add schematic symbols to the schematic. The most correct way to make a Pico add-on board would be to place a Pico in the schematic and connect everything to it, but you are going to use a workaround to do this in a much simpler way. The main idea of the target add-on board is for you to be able to solder in rows of header sockets so that you can connect it onto the pins of a Pico. In turn, you also still want to be able to solder to those pins, so you need each side row of pins to be broken out to another collection of pads.

为此,请在原理图两侧各添加一个 20 针连接器。要添加第一个连接器,请单击“添加符号”图标——右侧列中的第三个图标。首次单击此图标时,原理图符号库可能需要几秒钟才能加载,之后系统会提示您选择要加载的库——请选择“复制默认全局封装库表(推荐)”选项。

To do this add two 20-pin connectors, one on each side of the schematic. To add the first one, click the Add a Symbol icon — the third icon down on the right-hand column. The first time you click this icon, it may take a few seconds for the libraries of schematic symbols to load and you will be offered a choice of which library to load — select the option Copy default global footprint library table (recommended).

加载完成后,会显示“选择符号”对话框。左侧会显示一个项目列表,每个项目都是一个(一组原理图符号)。这些库按相关项目分组。例如,您可能会在列表顶部看到“4xxx”。单击其旁边的下拉菜单按钮,即可显示包含 CMOS 4000 系列逻辑芯片的库。您可以手动滚动浏览库并查看其中包含的项目,也可以搜索库以查找所需内容。

Once loaded, the Choose Symbol dialogue appears. On the left-hand side, you’ll see a list of items, each of which is a library (a group of schematic symbols). These are grouped as related items. So, you might find, at the top of the list, 4xxx. If you click on the drop-down menu button next to it, it will reveal a library full of the CMOS 4000 series of logic chips. You can manually scroll through the libraries and look through the items they contain, but you can also search the libraries to find what you need.

您将添加一个连接器符号,代表您最终想要安装的 20 针接头。为此,请在搜索栏中输入“conn”,输入时,您应该会注意到列表项现在都是以“conn”开头的项。向下滚动列表,选择名为“Conn_01x20_Pin”的项,然后单击窗口右下角的“确定”按钮(图 1-4)。

You are going to add a connector symbol that represents the 20-pin header you eventually want to be able to fit. To do this, type conn into the search bar and, as you type, you should notice the list items are now all the items that start conn. Scroll down the list and select the item that reads Conn_01x20_Pin, and then click the OK button in the lower right-hand corner of the window (Figure 1-4).

图 1-4:选择符号对话框,允许您搜索原理图符号

“选择符号”窗口将关闭,您将返回原理图编辑器,此时指针应该会指向一个 20 针插座的符号。将指针移动到您想要放置连接器的位置,然后单击以放置它。

The Choose Symbol window will close, and you will be back in the Schematic Editor, where you should have a symbol for the 20-pin socket attached to your pointer. Move the pointer to where you want to place the connector and click to place it.

一大袋插座

A sackload of sockets

您将在原理图中再添加三个 20 针连接器。再次单击“添加符号”工具图标,但请注意,随着库列表区域的填充,顶部会出现一个“最近使用”区域,其中列出了 20 针连接器(您可能需要滚动库列表区域才能看到它)。单击此列表,然后单击“确定”,再将下一个连接器添加到原理图中。重复此操作,直到添加四个连接器。

You are going to place three more of 20 pin connectors into the schematic. Click the Add a Symbol tool icon again, but notice that, as the library list area populates, you now have a Recently Used area at the top with the 20-pin connector listed underneath (you may need to scroll the library list area to the top to see this). Click this listing and then OK, then place the next connector in the schematic. Repeat this until you have placed four of the connectors.

接下来,使用M(移动)快捷键移动连接器,使两对连接器并排排列。其中一对连接器位于 Pico 的左侧,一个连接器是 Pico 引脚的插孔,另一个连接器是用于连接其他硬件的插孔。另一对连接器位于右侧,情况相同。

Next, use the M (Move) hotkey to move the connectors so that there are two pairs of connectors next to each other. One pair of headers corresponds to the left side of the Pico with one header being the holes for the Pico’s pins and one header being holes to attach additional hardware. The other pair is the same thing but on the right-hand side.

键盘侠

虽然在 KiCad 中所有操作都可以用鼠标和指针完成,但学习一些快捷键能让工作更轻松。许多按键在原理图编辑器PCB 编辑器中都能实现相同的功能。

Whilst you can do everything in KiCad with a mouse and pointer, it’s worth learning a few quick keyboard shortcuts to make life easier. Many keystrokes offer the same functions in both the Schematic Editor and the PCB Editor.

首先要介绍的是用于缩放的F1F2键。按下F1键放大,按下F2 键缩小。请注意,这两个键的缩放中心都以鼠标指针所在位置为中心。稍加练习,您就能熟练地移动鼠标指针并进行缩放,从而获得所需的视图。

The first useful ones are the F1 and F2 keys for zooming. The F1 key, when pressed, will zoom in, and F2 will zoom out. Note that both are centred around where your pointer is. With a little practice, it becomes second nature to move the pointer and zoom in and out to get the view you need.

接下来是MR键。如果您在原理图编辑器或 PCB 编辑器中选中一个对象,可以按M键,该对象会移动,直到您再次单击将其放置到位。在 PCB 编辑器中,您可以选择比元件完整封装更小的部分。例如,您可以选择并移动丝印标签等等。如果要选择整个元件,选择元件焊盘通常会选中整个封装。

Next up are the M and R keys. If you select an object in the Schematic Editor or the PCB Editor, you can press M and then that object will move until you click to place the object again. In the PCB Editor, you can select smaller parts than the complete footprint of a component. You can, for example, select and move silkscreen labels and more. If you want to select the whole component, selecting a component pad will usually select the entire footprint.

使用R键,您可以在任一编辑器中旋转选定的项目,旋转到正确位置后,单击即可放置该项目。请注意,您可以反复旋转该项目,直至达到所需的方向。

With the R key, you can rotate a selected item in either editor, again single-clicking to place the part when rotated correctly. Note that you can rotate the item repeatedly to get to the orientation you require.

最后,还有一个很有用的快捷键是E键。选中某个项目后,按下E键即可编辑该项目的属性。这些属性包括各种可编辑参数,例如标签、焊盘尺寸、孔径等等。

Finally, another useful shortcut is the E key. With an item selected, pressing the E key allows you to edit that item’s properties. This can be any number of editable parameters, from labels to pad sizes to hole dimensions and more.

使用快捷键(例如M)时,只需将光标悬停在符号上,然后按下快捷键即可——无需先选中符号。快捷键可以作用于整个符号及其各个部分。要选中整个连接器,最简单的方法是将光标放在组件内部的空白区域,然后按下快捷键。可能需要尝试几次才能熟练掌握。如果难以将光标放在正确的位置,可以尝试稍微放大视图。

When using hot keys like M, place the cursor over the symbol and then press the key — there’s no need to highlight the symbol first. The hot key can work on the complete symbol as well as individual parts of it. The easiest way of grabbing the whole connector is to place your cursor in a bit of blank space inside the component, then press the key. It might take a few attempts to get the hang of it. If you find it hard to get your cursor in the right place, try zooming in a little.

现在你应该有两对连接器,为了方便连接电线,你需要将电线连接到连接器内侧的小圆圈上——这些圆圈就是你要连接电线的地方,而且电线不要穿过圆圈,这样看起来会更整齐。你可以使用X(水平镜像)快捷键来完成这个操作。你只需要对每对连接器中最右边的那个进行此操作即可。

You should now have two pairs of connectors, but to make it easier to connect the wires, you’ll want the little circles on the inside of the pair — these are the bits you’ll connect the wires to and it’s a bit tidier if the wires don’t go across the symbol. You can do this using the X (Mirror Horizontally) hot key. You’ll only need to do this for the rightmost connector in each pair.

虽然这次你不需要用到它,但R(旋转)快捷键通常也有助于将零件调整到合适的位置。

Although you don’t need it this time, the R (Rotate) hotkey is often also useful for getting your parts in a useful place.

使用“添加导线”(单击工具箱中的图标或按W键)工具,您可以单击其中一个连接器引脚圆圈,然后绘制一条导线连接到对面的连接器引脚(图 1-5)。如果操作失误,可以使用Ctrl+Z撤销上一步操作;或者,要在绘制过程中取消导线,可以右键单击并从下拉菜单中选择“取消” 。

Using the Add a Wire (click on the icon in the toolbox or press W) tool, you can click on one of the connector pin circles and then draw a connector wire line across to the opposite connector pin (Figure 1-5). If you make a mistake, you can use CTRL+Z to undo the last action — or, to cancel the wire mid-draw, you can right-click and select Cancel from the drop-down menu.

图 1-5:在原理图符号的引脚之间添加导线连接

继续连接每对连接器上相对的引脚,直到所有连接器都连接在一起。请注意,每个连接器符号都包含一些文本说明。建议您编辑这些说明,使其更易于理解和记忆。选中其中一个连接器符号(使用选择工具框选整个符号),将光标悬停在该符号上,然后按E键。

Continue to wire between each of the opposite pins on each connector pairs until they are all connected together. Notice that each of the connector symbols have a couple of text references as part of them. It can be good practice to edit these so that they are useful and help you keep track of what things are. Select the whole of one of the connector symbols (use the selection tool to draw a box over the entire symbol), put the cursor over the symbol, and then press E.

现在您应该会看到“符号属性”对话框(图 1-6)。您可以编辑“参考”(如果需要)和“值”文本条目。您应该为每个连接器指定一个描述性值,例如“左侧 Pico”。这在 PCB 编辑器中布局 PCB 时非常有用,因为它可以确保您能够正确识别各种连接器。

You should now see a Symbol Properties dialogue box (Figure 1-6). You can now edit the Reference (if required) and the Value text entries. You should give each connector a descriptive Value such as Left Pico. This is useful when you lay out the PCB in the PCB Editor, as it ensures you can identify the various connectors correctly.

图 1-6:编辑符号属性可以赋予符号更有意义的名称

为了完成原理图,添加一个电阻和一个LED,并将它们连接到Pico的38号引脚(GND)和36号引脚(3.3V(输出))。这两个引脚分别是右侧连接器上的第三个和第五个引脚。使用之前选择符号的相同方法,搜索“R”表示电阻,搜索“ LED”表示LED 。如图1-7所示,添加导线连接电路。如果需要,可以使用快捷键“R”旋转符号。

To finish the schematic, add a resistor and an LED and connect them to pins 38 (GND) and 36 (3V3 (OUT)) on Pico. These pins are the third pin and fifth pin down on the right-hand connector. Use the same techniques you used earlier to choose a symbol, searching R for a resistor and LED for an LED symbol. Add wires to connect the circuit, as shown in Figure 1-7. Use the R hotkey to rotate symbols if needed.

图 1-7:在原理图中添加电阻器和 LED

已开启

Switched on

接下来,添加一个开关符号,将其连接成 Pico 的复位按钮。

Next, add a switch symbol which you will wire in as a reset button for the Pico.

添加复位按钮很好地体现了 KiCad 与其他一些电子设计自动化 (EDA) 工具的不同之处。在某些 EDA 工具中,您在原理图级别选择的符号会精确定义 PCB 上电子元件的硬件封装。

Adding a reset button is a good example of a way that KiCad works differently to some other Electronic Design Automation (EDA) tools. In some EDA tools, the symbol you choose at the schematic level defines exactly the hardware package of the electronic component that will be on the PCB.

在其他EDA工具中,您不会放置通用的电阻符号,而是放置与特定电阻关联的电阻符号,例如一个6mm长、1/4瓦的水平放置的碳膜电阻。这意味着,如果您想更改PCB上的元件,则必须修改原理图。在KiCad中,原理图符号仅分配一个 封装——这就是为什么您要放置一个单刀单掷开关(SPST)的符号,但实际元件可以是任何SPST开关或任何按钮封装。在本例中,您将选择某种瞬时按钮作为复位按钮。这种工作方式意味着,如果您发现需要用不同类型的元件替换某个元件(例如,如果您找不到库存元件),您只需更改与符号关联的封装,而无需编辑原理图。它还能使原理图简洁易读,这对于共享设计至关重要。

In other EDA tools, you wouldn’t place a generic resistor symbol, you would place a resistor symbol linked to a specific resistor, say a 6mm long 1/4-watt carbon resistor placed horizontally. This would mean that, if you wanted to change the component on the PCB, you have to change the schematic. In KiCad, the schematic symbol is only assigned a footprint — this is why you are going to place a symbol for a single-pole single-throw switch (SPST), but the actual component can be any SPST switch or any button package. In this case, you’ll choose some type of momentary push-button for the reset. This way of working means that if you find you need to replace a component with a different type (for example, if you can’t find a component in stock), you simply change the footprint associated with the symbol and don’t have to edit your schematic. It also makes the schematics concise and readable, which is important if you want to share your design.

要添加开关,请在“选择符号”对话框中搜索sw_spst,即可直接找到单刀单掷开关,然后按照图 1-8所示连接导线。最后,添加四个连接器作为电路板上的原型区域;搜索conn_01x04即可直接找到该符号。现在,您的原理图应该如图 1-9所示。

To add the switch, search the Choose a Symbol dialogue with sw_spst to take you directly to the single-pole single-throw switch and again connect wires, as shown in Figure 1-8. Finally, add four connectors to act as prototyping areas on the board; search for conn_01x04 to take you directly to this symbol. You should now have a schematic that looks like Figure 1-9.

图 1-8:在原理图中添加一个单刀单掷开关,用作复位按钮
图 1-9:完整电路图

让我们为每个原理图符号设置关联的封装。转到“工具”>“分配封装”。此时将出现“分配封装”对话框(图 1-10),左侧是封装库列表,中间部分是项目中原理图符号的列表,右侧是筛选后的封装结果。窗口顶部有三个名为“封装过滤器”的图标,稍后您会看到,选择第二个图标(按引脚数筛选)会很有帮助。随着您逐渐熟悉元件筛选,您可能会发现自己更喜欢使用这些筛选工具的不同组合。

Let’s set up the associated footprints for each schematic symbol. Go to Tools > Assign Footprints. The Assign Footprints dialogue (Figure 1-10) appears with a list of footprint libraries down the left-hand side, a centre section with a list of schematic symbols in the project, and a right-hand column of filtered footprint results. There are three icons at the top of the window called Footprint Filters and, as you’ll see in a moment, it’s helpful to select the second of these (Filter by pin count). As you get used to component filtering, you might find you prefer to use different combinations of these filtering tools.

图 1-10:分配足迹对话框

在中心区域选中一个 20 针连接器元件。你需要找到一个引脚数相同且每个引脚都对应一个通孔焊盘的封装。由于 Raspberry Pi Pico 的引脚间距为常见的 2.54mm,因此你还需要确保封装的间距与之相同。右侧应该会显示一个筛选列表——该列表应仅包含与 20 针连接器符号对应的元件。从连接器封装库中选择 Connector_PinSocket_2.54mm :Pinsocket_1x20_P2.54mm_vertical。单击一次以在列表中选中该元件,然后使用“在封装查看器中查看所选封装”工具图标(从左数第三个图标)打开一个窗口,显示 PCB 封装布局设计,以检查其是否正确。 双击选中的封装,将其与中心列表中选定的原理图符号关联起来。继续操作,将相同的封装添加到所有四个连接器符号列表中(稍后我们将讨论为什么这样做并不完全正确,但对于这个入门项目来说没问题)。单击“应用、保存原理图并继续”按钮

Highlight one of the 20-pin connector components in the centre section. You need to find a footprint that has the same number of pins and has a footprint of a through-hole pad for each pin. As the Raspberry Pi Pico pins are spaced at the common 2.54mm pitch between each pin, you also need to make sure the footprint is spaced similarly. You should have a filtered list on the right-hand side — it should be filtered to only contain items that would attach to the 20-pin connector symbol. Choose Connector_PinSocket_2.54mm:Pinsocket_1x20_P2.54mm_vertical from the connector footprint library. Click once on the item to highlight it in the list, then use the View the selected footprint in the footprint viewer tool icon (third icon from the left) to open a window showing the PCB footprint layout design to check if it looks correct. Double-click the highlighted footprint to associate it with the selected schematic symbol in the central list. Continue and add the same footprint to all four connector symbol listings (we’ll discuss later why that isn’t totally correct, but it’s fine for this starter project). Click the Apply, save schematic and continue button.

您还需要添加 LED、电阻和按钮的表面贴装元件;请选择易于手工焊接的 SMD 封装尺寸和焊盘。LED 选择 LED_SMD :LED_0805_2012Metric焊盘;电阻选择Resistor_SMD:R_0805_2012Metric 焊盘;开关选择Button_Switch_SMD:SW_SPST_B3SL-1002P元件。对于分离式 4 针连接器,每个连接器选择Connector_PinSocket_2.54mm:PinSocket_1x04_P2.54mm_Vertical 焊盘 。分配完所有焊盘后,单击“应用”,保存原理图并继续,然后单击“确定”。

You’ll also need to add surface-mount components for the LED, resistor, and the button; you’ll choose SMD package sizes and footprints that are easy to hand-solder. For the LED, choose the LED_SMD:LED_0805_2012Metric footprint; for the resistor, the Resistor_SMD:R_0805_2012Metric; and for the switch, a Button_Switch_SMD:SW_SPST_B3SL-1002P component. For the detached 4-pin connectors, select Connector_PinSocket_2.54mm:PinSocket_1x04_P2.54mm_Vertical for each connector. With all those footprints assigned, click Apply, save schematic and continue, then click OK.

在下一章中,您将把元件封装列表导入 PCB 编辑器,并实际布局电路板设计,使其准备好进行制造。

In the next chapter, you will import the list of component footprints into the PCB Editor and physically lay out the board design to get it ready for fabrication.

添加部件

正如本章所述,KiCad 使用原理图符号和元件封装来创建原理图和 PCB 设计。您应该已经拥有许多内置的标准库,本项目中的所有内容都只是使用了这些库。当然,您也可以创建自己的原理图符号、元件封装,甚至是元件的 3D 模型,并将它们集成到您自己的设计中,从而创建自定义库。我们将在后续章节中详细介绍这些内容以及更多其他知识。

As you can tell from this chapter, KiCad uses schematic symbols and component footprints to create schematics and PCB designs. You should have a lot of standard libraries built in, and everything in this project is just using these libraries. Of course though, you can create your own schematic symbols, component footprints, and even 3D models of components and incorporate these into your own designs creating custom libraries. We’ll cover this, and lots more in future chapters.

第二章

Chapter 2

PCB布局

Laying out a PCB

将原理图转化为物理设计

Turn a schematic into a physical design

上一章中,您绘制了树莓派 Pico 扩展板的原理图,并为每个原理图符号分配了代表相应元件的封装。本章中,您将完成这个入门项目,设计 PCB 布局,为生产做好准备。

In the last chapter, you created a schematic for a Raspberry Pi Pico add-on board, and assigned each schematic symbol a footprint which represents the individual component using. In this chapter, you’ll finish this starter project by laying out the PCB design, ready for manufacture.

图 2-1:本章中您将设计的布线 PCB。

在 KiCad 中打开之前的项目,然后从可用应用程序列表中选择PCB 编辑器 图标。如果您是在原理图编辑器中打开的项目,请单击原理图编辑器工具栏中的 PCB 编辑器图标跳转到该编辑器。

Open the previous project in KiCad and select the PCB Editor icon from the available applications. If you have opened the project in the Schematic Editor, jump to the PCB Editor by clicking its icon in the Schematic Editor toolbar.

打开PCB编辑器后,您应该会看到一个与原理图编辑器类似的页面,但页面是黑色的(图2-2)。您会发现它是空白的,因此第一步是导入封装。

Having opened the PCB Editor, you should see a similar page to the Schematic Editor, but in black (Figure 2-2). You’ll notice it is blank, so the first action is to pull in the footprints.

在放置封装之前,我们先更改一个设置。PCB 编辑器具有网格功能,可以将封装吸附到合适的位置。在本例中,引脚插座封装将吸附到网格上焊盘孔的中心。由于 Pico 采用 2.54mm 的引脚间距,因此此时将电路板编辑器的网格设置为2.54mm(100 mil)会很有帮助。您可以从顶部工具栏中间的下拉菜单中选择此设置。

Let’s change one setting before placing the footprints. The PCB editor has a grid feature which snaps footprints at useful points. In the current case, the pin socket footprints will snap with the centres of the pad holes on the grid. As Pico conforms to 2.54mm pin spacings, it’s useful at this point to set the board editor grid to 2.54mm (100 mils). You can select this from the centre drop-down menu on the upper toolbar.

接下来,点击“从原理图更新PCB”图标(顶部工具栏从右数第四个图标,或按F8键)。这将打开一个对话框,您只需点击“更新PCB”按钮,然后点击“关闭”按钮(图2-3)。“从原理图更新PCB”对话框会导入元件封装和连接信息,可用于对原理图设计进行后续更改。返回PCB编辑器后,您现在应该可以看到一组封装,它们会附加到您的鼠标指针上。点击即可将元件包放置在页面中间的某个位置(图2-4)。

Next, click the Update PCB from Schematic icon (4th icon from the right in the top toolbar or press F8). This opens a dialogue, and you can simply click the Update PCB button and then click the Close button (Figure 2-3). The Update PCB from Schematic dialogue brings in the component footprints and connectivity and can be used to apply future changes to a schematic design. Once back in the PCB Editor, you now should have the design as a collection of footprints attached to your mouse pointer. Click to place the component bundle somewhere in the middle of the page (Figure 2-4).

图 2-2:空白的 PCB 编辑器,准备导入封装
图 2-3:从原理图更新PCB对话框
图 2-4:导入的元件封装,图中“鼠窝”状区域表示元件之间的连接,焊盘由细线组成。

密耳(mil)是等于0.001英寸的计量单位。它在PCB领域很常见,容易与毫米(mm)混淆。

Mil is a unit of measurement that’s equal to 0.001 inches. It’s common in the PCB world, and easily confused with mm.

现在您可以将两对引脚插座的焊盘对齐,使它们在水平方向上彼此对齐。

You can now align the two pairs of pin socket footprints so that they are in line with each other horizontally.

小贴士

请记住,很多键盘快捷键都是通用的。例如,F1F2缩放功能在原理图编辑器和 PCB 编辑器中都有效。

Remember, a lot of your keyboard shortcuts are universal. For example, F1 and F2 zooming works in both the Schematic Editor and the PCB Editor.

首先移动标记为“左侧 Pico”的封装:确保右侧工具栏中已选中“选择项目”工具,然后单击封装上焊盘的中心并按M键(类似于您在原理图编辑器中的操作)。将其移动约十个网格点,然后单击以放置。移动过程中,您应该会注意到连接两个相邻封装之间焊盘的一系列白色细线——这被称为“鼠窝”。在绘制走线连接时,您将移除这些白色细线。

Start by moving the footprint labelled Left Pico: make sure the Select item(s) tool is selected on the right-hand toolbar, then click on the centre of a pad on the footprint and press M (similar to how you worked with the Schematic Editor). Move it about ten grid dots and click to place it. As you move it, you should notice a collection of small white lines connecting the pads between the two connected footprints — this is called the rat’s nest. You will remove these white lines when you lay the trace connections.

电路板与 Pico 的尺寸匹配至关重要,因此我们使用了Pico 数据手册中的尺寸图(图 2-5) ,该数据手册可在hsmag.cc/PicoDatasheet获取。您会注意到,垂直引脚行之间的距离为 17.78 毫米,相当于 7 × 2.54 毫米。这种间距在电子领域很常见,这也是为什么您的 Pico 可以完美地安装在原型面包板上的原因。

It’s important that the board matches up to Pico, so we used the dimensional diagram (Figure 2-5) taken from the Pico Data Sheet, available at hsmag.cc/PicoDatasheet. You’ll notice that the distance between the vertical rows of pins is 17.78mm — this equates to 7 × 2.54mm. This spacing is common in electronics — it’s why your Pico fits perfectly into a prototyping breadboard.

图 2-5:取自数据手册的 Pico 技术图纸,为您提供所需的尺寸信息。

单击右侧 Pico 封装,然后再次按M键。移动鼠标,使右侧 Pico 封装与左侧 Pico 封装对齐,然后将右侧 Pico 封装向右移动七个网格点。

Click the Right Pico footprint, and again press M. Move the mouse to align the Right Pico footprint on top of the Left Pico footprint, and then move the Right Pico footprint seven grid spots to the right.

在接下来的元件布局中,您可以将网格尺寸更改为1.2700 毫米(50 密耳),这样可以更好地调整元件布局。现在,您可以将左侧扩展板的封装放置在左侧 Pico 右侧两个网格点的位置,将右侧扩展板的封装放置在右侧 Pico 左侧两个网格点的位置。此时,外侧的两个封装应该与 Pico 的引脚位置完全匹配,内侧的两个封装应该靠近它们并平行放置。您可以使用测量工具(右侧工具栏底部的标尺图标)来确认外侧两个封装之间的距离为 17.78 毫米。

For the remainder of the component placing, you can get things to fit a bit better if you change the grid size to 1.2700mm (50 mils). You can now arrange the Left Breakout footprint to be two grid spots to the right of the Left Pico, and the Right Breakout footprint two grid spots to the left of the Right Pico. The outside pair of footprints should now match Pico’s pin positions, and the inner footprints should be close to them, and parallel. You can use the Measure tool (the ruler-shaped icon at the bottom of the right-hand toolbar) to confirm that the distance between the outer two footprints is 17.78mm.

到目前为止,您应该只在F.Cu(PgUp)层上操作,也就是 PCB 板上的顶层铜箔层。在布线之前,请务必通过顶部工具栏的下拉菜单确认您当前位于该层。

So far, you should have only been working on the F.Cu (PgUp) layer, which is the top copper layer on the PCB board. Before you route the tracks between the footprints, double-check that you are on this layer by checking the drop-down menu on the top toolbar.

除了脚印什么都不要留下

Leave only footprints

接下来,您可以将相对焊盘上的焊盘连接起来(图 2-6)。为此,请选择“布线 (X)”图标,然后单击一个焊盘的中心,并将走线拖动到相对焊盘的中心。走线应为红色,表示它位于顶层铜箔上。例如,如果您移动到​​B.Cu (PgDn)层,则底层铜箔上的走线默认颜色为蓝色。继续连接所有焊盘,您会发现连接过程中杂乱的线路会消失。

Next, you can wire the pads on the opposite footprints together (Figure 2-6). To do this, select the Route Tracks (X) icon, then click the centre of a pad and drag the track over to the centre of the opposite pad. The track should be red, indicating that it’s on the top copper layer. If you, for example, were to move to the B.Cu (PgDn) layer, the default colour for tracks on the lower copper layer is blue. Continue and connect all pads together, noticing that the rat’s nest lines disappear as you do so.

图 2-6:连接板上的焊盘

参考 Pico 技术图纸,现在是定义电路板形状和边缘的好时机。为此,您可以使用最上方的下拉菜单,从F.Cu(PgUp)图层切换到Edge.Cuts图层。在该图层上,您将使用“绘制矩形”工具为电路板创建切口形状。但在选择此工具之前,请将网格间距切换到更合适的值。选择 1mm 网格间距,然后单击矩形工具。在 PCB 编辑器页面中单击任意位置并拖动一个矩形(图 2-7)。它不必覆盖其他元件,因为您将在下一步中移动它。

Referring to the Pico technical drawing, it’s a good time to define the shape and edges of the board. To do this, you can use the uppermost drop-down menu to move from the F.Cu (PgUp) layer to the Edge.Cuts layer. On this layer, you will use the Draw a Rectangle tool to create a cutout shape for the board. But before you select this tool, switch the grid to a more useful spacing. Select the 1mm grid spacing, then click the rectangle tool. Click anywhere in the PCB Editor page and drag a rectangle (Figure 2-7). It doesn’t have to be over the other components because you’ll move it in the next step.

图 2-7:板的轮廓是 Edge.Cuts 层中的一个矩形。

矩形应自动吸附到网格上,然后将其拖动,直到标签显示其宽度为 21 毫米,高度为 51 毫米。再次单击以创建矩形。返回“选择项目”工具,现在选中矩形并按M键将其移动到所需位置。从 Pico 技术图纸中可以看到,Pico 的外边缘距离密码键盘中心 1.61 毫米。为了精确定位,应将网格间距缩小到最小值,并使用以下方法测量页面上的距离。

The rectangle should snap to the grid, and you should drag it out until the labels tell you that it’s 21mm wide by 51mm high. Click one more time to create the rectangle. Moving back to the Select Items (s) tool, you should now select the rectangle and press the M key to move it into position. Notice from the Pico technical drawing that the outside edge of the Pico sits 1.61mm from the centre of the pin pad position. To position this accurately, you should reduce the grid spacing to the smallest listed and use the following technique to measure distances on the page.

在 PCB 编辑器中,如果您按下空格键,可能会注意到标记为dxdydist的值被设置为零。这非常有用,因为您可以将指针放在某个点上,例如右上角焊盘的中心,按下空格键创建一个零点或基准点,然后将指针移动到(在本例中)边缘切割矩形。之后,您可以使用dxdy值来帮助您精确定位该矩形或任何其他需要定位的元素。

If you press the space bar at any time when in the PCB Editor, you might notice that values labelled dx, dy, and dist are set to zero. This is very useful as you can place your pointer at a point, say the centre of the top rightmost pad, press the SPACE bar to create a zero or datum point, and then move the pointer to, in this case, the edge cut rectangle. You can then use the dx and dy values to help you position this, or anything you need to, accurately.

小贴士

实际上,在添加边缘切割之前,您可以在 3D 查看器中查看电路板,它将渲染成一个最小的矩形尺寸,以容纳 PCB 上当前所有封装。

You can actually look at the board in the 3D Viewer before adding an edge cut, and it will render to a rectangle size that is the smallest that can accommodate all the footprints currently in the PCB.

正确定位电路板边缘矩形后,即可在 3D 查看器中初步查看电路板。要查看 PCB,请点击“视图”>“3D 查看器”。您将看到电路板,但会注意到所有排针插座的 3D 模型都放置在相应的孔位中。实际上,您只需要在电路板背面安装外侧几排的排针,内侧几排则保持空置,或者安装排针。您可以编辑电路板和元件封装以反映这一点,但在这个简单的示例中,您可以点击“切换通孔元件的3D 模型(T)”图标来关闭这些模型(图 2-8)。在后续章节中,我们将探讨如何使用正确的 3D 模型,以及如何添加自定义 3D 模型。

Once you have positioned the board edge rectangle correctly, you can get a first glimpse of the board in the 3D Viewer. To view the PCB, click View > 3D Viewer. You’ll see the board, but you’ll notice that all the 3D models of the header sockets are all placed into the rows of holes. In reality, you would only want headers on the outer rows installed on the back of the board, with the inner rows left unpopulated, or possibly populated with header pins. You could edit the board and the component footprints to reflect this, but for this simple example, you can click the Toggle 3D Models for Through Hole type Components (T) icon to turn off the models (Figure 2-8). In future chapters, we’ll explore not only using correct 3D models but will look at how you can add custom 3D models too.

图 2-8:渲染后的 PCB 板初视图

保持距离

Keep your distance

现在您可以继续排列和连接剩余的元件。为了使元件排列整齐,您需要切换到 0.635mm 的网格,并且可能需要使用R快捷键旋转开关。您会发现需要稍微重叠一些封装。这样做时,您需要了解封装的每个部分所显示的内容。

You can now continue to arrange and wire the remaining components. In order to fit the components, you’ll need to switch to the 0.635mm grid, and you may need to rotate the switch using the R hotkey. You’ll find that you need to overlap some of the footprints slightly. When doing this, you need to understand what each part of the footprint is showing.

紫色方框标示了元件的最大尺寸。正常情况下,这些尺寸不应重叠。但是,对于排针来说,您实际上并不会添加物理排针(您只是利用这个封装在正确的位置提供一系列通孔)。因此,这些紫色矩形可以略微重叠。浅黄色线条是丝印——也就是印刷在PCB上的图案。同样,对于这块电路板,只要不影响实际元件,这些图案可以略微重叠。随着电路板上实际元件数量的增加,您需要更加注意避免元件之间相互干扰。

The purple box around it shows the maximum size of the component. In normal usage, these shouldn’t overlap. However, in the case of the headers, you’re not actually going to add physical headers (you’re just using this footprint to give you a series of through holes in the right place). Therefore, it’s fine to overlap these purple rectangles slightly. The pale yellow lines are silkscreen — basically, graphics that are printed onto the PCB. Again, for this board, these can overlap slightly provided it won’t interfere with actual components. As you move onto boards with more actual parts on them, you’ll need to be much more careful about things not getting in the way of each other.

已分配并密封

本项目前面提到的一点是,KiCad原理图符号是通用的——您可以使用“分配封装”工具为它们指定硬件封装。这样做的好处是:假设您已经完成了PCB布局并准备生产,但在检查后发现B3SL-1002P按钮封装目前缺货。您可以返回原理图编辑器,点击“分配封装”工具图标。然后,您可以编辑SW_SPST符号,将其替换为其他(希望有库存的)元件。例如,选择B3SL-1022P封装,双击以确保将其添加到中控台列表中。然后,您可以点击“应用”>“保存原理图”>“继续”,最后点击“确定”关闭对话框。返回PCB编辑器后,您可以再次点击“使用原理图更改更新PCB (F8)”图标,或者按下键盘上的F8键,电路板将更新并添加替换封装。如果像本例中那样,用封装尺寸几乎相同的零件替换原零件,则可能不需要重新连接线路,但当然,您应该根据需要检查和调整连接和位置。

One point mentioned earlier in this project is the idea that KiCad schematic symbols are generic — you assign the hardware footprint to them using the Assign Footprint tools. Here’s the advantage of this. Say you have a PCB layout completed and ready for manufacture, but after checking, you realise that the B3SL-1002P button package is not available or in stock anywhere. You can simply go back to the Schematic Editor and click the Assign Footprint tool icon. You can then edit the SW_SPST symbol to have a different, and hopefully, in stock, component. For example, select the B3SL-1022P footprint package, double-clicking it to ensure it is added to the centre console list. You can then click Apply > Save Schematic > Continue, and then click OK to close the dialogue. Moving back to the PCB Editor, you can once again click the Update PCB with changes made to the schematic (F8) icon, or press F8 on the keyboard and the board will update with the replacement footprint added. If, as in this example, you replace the part with another part that is virtually the same footprint, you might not need to rewire the traces, but, of course, you should check and adjust connections and positioning as required.

对于 LED 和按钮,您需要将走线直接连接到 Pico 的引脚。您会发现必须将走线穿过其他元件。每条走线都必须避开其他元件的焊盘和通孔,但只要避开这些,就可以穿过封装。右键单击即可为导线添加一个弯曲点。

For the LED and the button, you need to wire traces directly to the pin connections to the Pico. You’ll find that you must weave the traces through other components. Each trace has to avoid pads and through holes of other components but can travel through the footprint as long as it misses these. A single right-click adds a bend point to a wire.

您可能需要将组件旋转 180 度,才能使连接线从正确的方向引出。您也可能会发现,减小网格尺寸可以更精确地放置走线,从而获得更好的效果。

You might find that you need to rotate a component through 180 degrees to make the connections come out of the right sides. You might also find that it works better if you decrease the grid size to allow you to place the tracks more precisely.

你的电路板布局比较拥挤,没有太多空间放置文字。你之前用来标记各个接头的标签在PCB布局完成后就不再需要了,所以你可以直接删除它们(点击文字并按删除键)。

You have quite a crowded board, and there’s not much space for text. The labels that you used to remind yourself which header is which are no longer needed once you’ve laid out the PCB, so you can simple delete these (click in the text and press the DELETE key).

最后,如何才能制作出这样的电路板呢?方法有很多——本书将逐一介绍。世界各地有很多公司提供电路板制造和组装服务。

Finally, how do you get this board made? Well, there are lots of options — we will look at many of them throughout this book. There are many services available from companies all over the world to manufacture and even assemble your boards.

图 2-9:本书中使用了多家 PCB 制造商,但 OSHPark 是一个很好的起点,您可以直接上传 KiCad PCB 文件。

这些服务在上传所需信息和文件方面可能需要不同的方法。通常,您需要导出PCB每一层的Gerber文件,以及显示孔的位置和尺寸的钻孔文件。一些公司可能对他们能够生产的孔径和电路板的公差有限制。我们将在后续章节中进一步探讨这一点,但如果您希望获得高质量的电路板,请将以.kicad_pcb结尾的文件上传到OSHPark网站(oshpark.com)。该网站和服务非常出色。它会在浏览器中生成您电路板的多个渲染图,您可以检查这些渲染图是否正确,然后再将PCB添加到购物车进行生产。几周之内——通常更短——您就能收到“完美的紫色PCB”。

These services may need different approaches in terms of what information and files you need to upload to get the job done. Often you’ll need to export Gerber files for each layer of the PCB, and also export drill files which show the position and size of holes. Some companies might have limitations on what size holes they can produce and what tolerance they can produce the board too. We’ll explore this further in future chapters, but if you want to get this board fabricated to an excellent standard, upload the file that ends with .kicad_pcb to the OSHPark website (oshpark.com). The website and service are brilliant. In-browser, it creates numerous renders of your board, which you can then inspect and check to see if they are correct before adding the PCB to your cart to be manufactured. In a few weeks — often less — you’ll have ‘Perfect Purple PCBs’ through your door.

第三章

Chapter 3

库、符号和足迹

Libraries, symbols and footprints

管理您的组件

Manage your components

本书前两章涵盖了制作适用于简单电路的基本PCB(例如带有少量附加元件的扩展板)所需的知识。本章将展示如何扩展KiCad的功能。我们将探讨如何从零开始创建库和符号,以及如何从其他来源导入和使用元件封装和原理图符号。此外,您还可以通过使用填充区域来标记常用连接点(例如所有接地电路点),从而提高电路板的质量。

In the first two chapters of this book, we covered enough to make a basic PCB suitable for simple circuits — a breakout board with some added components. In this chapter, we show how you can expand the capabilities of what you can make in KiCad. We’ll explore both creating libraries and symbols from scratch, but also importing and using component footprints and schematic symbols from other sources. You’ll also improve the quality of the boards by using flooded areas for common connections, such as all the circuit points that are connected to ground.

图 3-1:已完成的电路板,准备安装焊接印章和 Pimoroni BMP280 模块

本章使用一个相对简单的设计来演示这些技巧——制作一块板上包含两个模块的PCB。在构建项目时,您经常会在面包板上搭建电子模块。这有助于测试和正确接线,但并不适合长期使用,因为导线可能会脱落,元件也可能丢失。定制PCB是将面包板项目移植到更坚固耐用的永久平台的理想选择。虽然本章不会详细介绍每个步骤,但项目文件可在hsmag.cc/kicad_book_files获取。结合前两章所学的知识和技巧,您应该能够重新创建这个项目。

This chapter uses a relatively simple design to show these techniques — making a PCB that essentially has two modules on board. Quite often, when building a project, you’ll work with electronics modules on breadboards. This helps test out things and get the wiring correct, but it’s not particularly suitable for long-term use, because wires can fall out and parts go astray. A custom PCB can be the perfect way to take a breadboard project to a permanent home that’s more rugged and usable. While this chapter won’t cover every step in complete detail, the project files are available at hsmag.cc/kicad_book_files, and the knowledge and techniques you learned in the first two chapters, in combination with this section, should let you recreate this project.

你应该下载这个项目并将其保存为参考,但要从一个空白项目开始,逐步构建它。

You should download this project and keep it as a reference, but start with a blank project as you build up to it.

本项目将 Solder Party Stamp 和 Pimoroni BMP280 模块连接起来,使最终的电路板能够用于测量和记录温度和气压。Solder Party Stamp 是一款优秀的电路板,其核心是 RP2040 芯片,操作方式与 Raspberry Pi Pico 类似。RP2040 的所有引脚都已引出,并采用 半孔排针,因此您可以直接将 Stamp 焊接在 PCB 的焊盘上,而无需使用排针。Stamp 还引出了 USB 接口和板载 LiPo 电池充电功能。这意味着,如果您添加 USB 接口,还可以添加 LiPo 电池,使项目成为独立的电源。Solder Party Stamp 文档齐全,并且是开源的。Solder Party 还发布了 Stamp 的 KiCad 原理图符号和 PCB 封装,因此您可以利用它们学习如何添加库并将这些有用的元素导入 KiCad。

This project connects a Solder Party Stamp and a Pimoroni BMP280 module so that the resulting board can be used to measure and log temperature and barometric pressure. The Solder Party Stamp is an excellent board that has an RP2040 at its heart and is operationally similar to a Raspberry Pi Pico. The RP2040 is fully broken out to header pins which are castellated, so you can also solder the Stamp onto a PCB's pads without having to use header pins. The Stamp has the USB connection broken out as well as on-board LiPo charging. This means if you add a USB connection, you can also add a LiPo cell and make the project stand-alone. The Solder Party Stamp is well-documented and is open source. Solder Party has also published KiCad schematic symbols and a PCB footprint for the Stamp, therefore you can use it to learn how to add libraries and import these useful items into KiCad.

首先,访问以下链接,即可找到 Solder Party Stamp 库组件:hsmag.cc/StampFootprints 。点击绿色“代码”按钮旁的下拉菜单,然后选择“下载 ZIP”选项下载库文件。将文件解压缩到您电脑上的某个位置。在您刚刚解压缩的文件夹集合中,将整个KiCad文件夹(注意:不是KiCad 5文件夹)移动到您想要存放其他外部 KiCad 库的位置。您应该在用户目录下为此创建一个文件夹。

To begin, go to the following link where you will find the Solder Party Stamp library components: hsmag.cc/StampFootprints. Click the drop-down menu on the green Code button, then select the Download ZIP option to download the libraries. Unzip the files somewhere on your machine. In the collection of folders you just unzipped, move the entire KiCad folder (N.B. not the KiCad 5 folder) to wherever you want to store your additional external KiCad libraries. You should have a folder set up in your home directory for this.

利用库

Leveraging libraries

打开 KiCad,在主页面中,点击“首选项”下拉菜单,然后选择“管理符号库”选项。这将打开一个包含两个选项卡的窗口:“全局库”选项卡和“项目特定”选项卡(图 3-2)。确保您位于“全局库”选项卡中,找到并点击小文件夹图标。导航到您下载的文件夹并打开它,找到名为KiCad_stamp_lib的文件夹。打开此文件夹,选择RP2040_Stamp.kicad.sym 文件,然后点击“打开”

Open KiCad and, in the main page, click the Preferences drop-down menu and then select the Manage Symbol Libraries option. This should open a window with two tabs: the Global Libraries tab and the Project Specific tab, (Figure 3-2). Ensuring you are on the Global Libraries tab, find and click the small folder icon. Navigate to the folder you downloaded and open it to find a folder called KiCad_stamp_lib. Open this folder and select RP2040_Stamp.kicad.sym and then click Open.

图 3-2:符号对话框,您可以在其中添加或删除原理图符号库

现在您应该能在“全局库”选项卡底部看到一个名为RP2040_Stamp的新库。如果您创建一个新项目并打开原理图编辑器,现在可以使用“添加符号”工具将 Solder Party Stamp 符号添加到原理图中。您可以通过搜索RP2040并确保从RP2040_Stamp 库中选择符号(而不是默认的RP2040符号)来完成此操作;或者,您也可以向下滚动库列表,选择RP2040_Stamp,然后选择RP2040_Stamp符号。

You should now see a new library listed at the bottom of the Global Libraries tab called RP2040_Stamp. If you create a new project and open the Schematic Editor, you can now use the Add a Symbol tool to place a Solder Party Stamp symbol into the schematic. You can do this by searching for RP2040 and making sure you select the symbol from the RP2040_Stamp library (rather than the stock RP2040 symbol) or by scrolling down the list of libraries, selecting RP2040_Stamp, and then selecting the RP2040_Stamp symbol.

添加封装库的操作步骤类似。同样,在 KiCad 主界面,点击“首选项”,然后点击“管理封装库”。在“全局库”选项卡中,点击小文件夹图标(图 3-3)。找到您下载的文件夹,找到KiCad_stamp_lib文件夹——再次打开该文件夹,但这次选择RP2040_Stamp.pretty文件夹,然后点击“打开”。您应该会看到里面有三个文件,但无需选择任何特定文件——只需再次点击“打开”即可。现在,回到“全局库”选项卡,您应该可以向下滚动并看到RP2040_Stamp库条目。您可以通过将正确的封装与您在原理图编辑器中放置的RP2040_Stamp符号关联起来来检查操作是否成功,然后您可以打开该元件并将其导入到 PCB 编辑器中。如果您需要回顾一下如何执行这些操作,我们在前面的章节中已经介绍过。

It’s a similar experience to add a footprint library. Again, in the KiCad landing page, click Preferences and then Manage Footprint Libraries. Again, on the Global Libraries tab, click the small folder icon (Figure 3-3). Navigate to the folder you downloaded and find KiCad_stamp_lib — open that folder once more but, this time, select the RP2040_Stamp.pretty folder and click Open. You should see three files inside, but you don’t need to select any particular one — just click Open again. Now, back on the Global Libraries tab, you should be able to scroll down and see an RP2040_Stamp library entry. You can check that this has all worked by associating the correct stamp footprint to the RP2040_Stamp symbol you placed in the Schematic Editor, and then you can open and import the part into the PCB Editor. If you need a reminder on how to do those tasks, we covered them in the previous chapters.

图 3-3:封装对话框,您可以在其中添加或删除 PCB 封装模块库

使用 BMP280 模块,您可以学习如何创建原理图符号和封装。为此,您需要创建自己的库来存放这些元件以及将来可能添加的其他元件。我们先从自定义原理图符号开始。在原理图编辑器中,单击“创建、删除和编辑符号”工具按钮。这将打开原理图符号编辑器。

Using the BMP280 module gives you an opportunity to learn how to make both a schematic symbol and a footprint. To do this you will create your own libraries to contain these parts, and others in the future. Let’s begin with a custom schematic symbol. In the Schematic Editor, click the Create, delete and edit symbols tool button. This opens the Schematic Symbol Editor.

在新窗口中,单击“文件”,然后从下拉菜单中选择“新建库” 。此时应该会看到一个名为“添加到库表”的小对话框。在此对话框中,您可以选择将新库添加到“全局”表。这意味着 KiCad 中的任何项目都可以访问此库;或者,如果您选择“项目”,则只有此 KiCad 项目可以访问该库。由于 BMP280 是您可能在其他项目中使用的对象,请确保选中“全局”,然后单击“确定”。接下来,系统会提示您为库命名——您可以随意命名,但请确保保留文件名中的“.kicad_sym”部分,然后单击“保存”

In this new window, click File and then select New Library from the drop-down menu. You should now see a small dialogue box called Add To Library Table. In this box, you can select to add your new library to the Global table. This means any project in KiCad can access this library; alternatively, if you select Project, only this KiCad project can access that library. As the BMP280 is something you might use in other projects, make sure Global is highlighted and then click OK. You’ll now be asked to give your library a name — it can be anything you want, so name it, making sure to leave the .kicad_sym part of the file name intact, and click Save.

现在您应该能在符号编辑器窗口左侧看到高亮显示的符号库名称。这意味着该符号库已激活,因此当您选择创建新符号时,它将被存储在该符号库中。

You should now see your new symbol library name highlighted on the left-hand side of the Symbol Editor window. This means that this is the active library, so that when you select to create a new symbol, it will be stored in this library.

点击“文件” ,然后从下拉菜单中选择“新建符号” 。此时应该会弹出“新建符号”对话框。给符号命名,该名称将出现在库列表中——最好选择一个能够反映元件特性的名称,例如:pi_bmp280。点击“确定”后,符号编辑器窗口中应该会出现一个“U”符号,并且该符号的名称会出现在屏幕左侧列表的活动库中。名称旁边会有一个星号(*),表示该符号尚未保存。

Click File and select New Symbol from the drop-down menu. You should see a New Symbol dialogue appear. Give your symbol a name that will be used in the library list — make it a useful name that reflects the part: pi_bmp280. Clicking OK, you should now see that a U has appeared in the Symbol Editor window and that the name of the symbol now appears in the active library in the list on the left-hand side of the screen. The name will have a * next to it, indicating that the symbol has not been saved.

符号编辑器中有一些熟悉的控件,例如F1F2键,用于放大和缩小。稍微缩小一下,给自己留出一些空间,就可以开始添加引脚了。

In the Symbol Editor there are some familiar controls, such as the F1 and F2 to zoom in and out. Zoom out a little to give yourself some room and you can get started by adding some pins.

点击“添加引脚”工具图标。在对话框中,您可以为引脚命名、编号、设置电气类型,并根据需要更改其他设置。对于第一个引脚,将其命名为“1” 2-6V_in,分配引脚编号“ 2 1”,并将电气类型设置为“电源输入”。继续添加引脚 2、3、4 和 5,并按照图 3-4所示进行标记。放置引脚时,请注意您可以使用通用快捷键M(移动)和R (旋转),类似于原理图或 PCB 编辑器中的操作。创建所有引脚后,使用“添加文本项”工具添加文本标签。这样,在查看原理图时,您可以快速识别符号。

Click the Add a pin tool icon. In the dialogue, you can name the pin, give it a number, set its Electrical type, and change other settings if needed. For the first pin, name it 2-6V_in, assign it pin number 1, and set the electrical type to Power input. Continue to add pins 2, 3, 4, and 5, labelling them as you can see in Figure 3-4. As you place pins, notice that you can use the generic hot keys M for move and R for rotate, similar to the Schematic or PCB Editors. Once you have all your pins created, add a text label using the Add a text item tool. This lets you identify the symbol quickly when looking at a schematic.

图 3-4:符号编辑器窗口可用于创建或编辑原理图符号

最后,在原理图符号周围绘制一个边界框,使所有元素整齐地组合在一起。单击“添加矩形”工具,在设计上绘制一个矩形。单击屏幕左上角的“保存”图标,然后关闭符号编辑器窗口。现在,您可以进入原理图编辑器,使用“添加符号”工具查找并添加您的第一个自定义符号。

Finally, draw a bounding box around the schematic symbol so that everything is neatly grouped together. Click the Add a rectangle tool and draw a rectangle over your design. Click the Save icon in the top-left corner of the screen, and then close the Symbol Editor window. You can now go into the Schematic Editor and use the Add a symbol tool to find and add your first custom symbol.

接下来,为 Pimoroni BMP280 模块创建一个新的封装库和封装。首先,打开封装编辑器(图 3-5)。您可以从 KiCad 主项目窗口或PCB 编辑器中的“创建、删除和编辑封装”工具图标打开它。与符号编辑器类似,打开封装编辑器后,首先单击“文件”,然后从下拉菜单中选择“新建库” 。选择将新库添加到“全局”“项目”表——选择“全局”并为您的库命名。新库出现在列表中后,选中它,然后单击“文件”并选择“新建封装”。此时将出现一个对话框,您可以在其中为新封装命名:Pim_BMP280_Module

Next, make a new footprint library and footprint for the Pimoroni BMP280 module. To begin, open the Footprint Editor (Figure 3-5). This is available from either the main KiCad project window or from the Create, delete and edit footprints tool icon in the PCB Editor. Similar to the Symbol Editor, once you have the Footprint Editor open, the first thing to do is to click File and then select New Library from the drop-down menu. Select to add a new library to the Global or Project table — select Global and name your library. Once the new library appears in the list, highlight it and then click File and select New Footprint. A dialogue appears and you can name your new footprint: Pim_BMP280_Module.

图 3-5:可以使用封装编辑器窗口创建或编辑元件封装。
小贴士

如果您使用来自外部库的原理图符号或封装模块,一旦将其保存到 KiCad 项目文件中,该符号/封装就会存储在该项目中。如果您在另一台安装了 KiCad 但没有添加自定义库的计算机上,您仍然可以像往常一样打开该项目。

If you use a schematic symbol or a footprint module from an external library, once it is saved in your KiCad project file, the symbol/footprint is stored in that project. If you moved to another machine with KiCad that didn’t have the custom libraries added, you would be able to open the project as usual.

您还需要点击下拉菜单,指定该元件是SMD(表面贴装)元件还是通孔元件。选择通孔元件,然后添加焊盘和其他封装部分。与PCB编辑器类似,您可以设置网格分辨率。由于BMP280模块的引脚间距为标准的2.54mm,因此建议初始时将网格设置为此值,以便轻松放置引脚。

You also need click the drop-down menu and specify whether this is an SMD or Through Hole component. Select Through Hole, then add the pads and other parts of the footprint. Similar to the PCB Editor, you can set the grid resolution and, as the pins on the BMP280 module are spaced at a standard 2.54mm pitch, it is worth setting the grid to this initially to allow you to easily place the pins.

接下来,点击“添加垫片”工具图标。你需要从左到右依次放置五个编号为 1 到 5 的垫片。最简单的方法是从中心基准线向外数两个网格间距,然后点击放置垫片 1。注意,“添加垫片”工具会递增垫片编号,因此下一个预览的垫片编号为2。将一个垫片移动到你刚刚创建的垫片的右侧,然后再次点击。重复此操作,直到你整齐地排列好五个垫片为止。

Next, click the Add a pad tool icon. You’ll need to end up with five pads labelled 1 to 5 moving from left to right. The easiest way to do this is to count two grid spacings out from the centre datum line and then click to place pad 1. Notice that the Add a pad tool then increments the pad number so the next previewed pad is labelled 2. Move one pad to the right of the pad you just made and click again. Continue until you have a neat row of five pads.

切换回“选择项目”工具,将鼠标悬停在焊盘 1 上,然后按E键打开“焊盘属性”对话框(图 3-6)。在此窗口中,您可以更改焊盘的几何形状、孔径以及更多选项。我们发现,将焊盘尺寸略微增大(高于默认值)并增大孔径,对于在模块之间焊接排针效果很好。您可能有自己的偏好,但我们将每个焊盘都编辑为直径 1.8 毫米、孔径 1 毫米的圆形。

Reverting to the general Select items tool, hover over pad 1 and press the E key to open the Pad Properties dialogue (Figure 3-6). In this window you can change the geometry of the pad, the size of the hole, and many more options. We’ve found that increasing the pad size slightly from the default, and increasing the hole size, works well for soldering header pins between modules. You may have your own preferences, but we edited each pad to be a 1.8mm circle with a 1mm hole.

图 3-6:使用“焊盘属性”对话框编辑焊盘大小和形状

焊盘制作完成后,下一步需要添加丝印图案,以表示模块实际占用的物理面积。许多元件的数据手册中都会列出封装尺寸,但对于专为原型设计和面包板应用而设计的模块来说,情况并非总是如此。在这种情况下,使用游标卡尺测量封装尺寸将有助于您获得实际尺寸。

With the pads created, you next need to add a silkscreen item that represents the physical area the module will occupy. Many components will have physical package dimensions listed in their datasheet, but that’s not always the case with modules that are really designed for prototyping and breadboard use. In these cases, some investigation with a pair of callipers will help you get the dimensions of the package.

测量 Pimoroni BMP280 后,我们发现引脚焊盘距离边缘 2.54 毫米处为 19 毫米见方的区域,这样可以为模块提供略微偏大的裕量,从而确保安全。选择屏幕右侧的F.Silkscreen图层,然后使用 “绘制矩形”工具绘制并正确放置该区域。

Measuring the Pimoroni BMP280, we realised a 19mm square area with the pin pads 2.54mm from the edge gives a slightly oversized and therefore safe margin for the module. Select the F.Silkscreen layer on the right-hand side of the screen and use the Draw a rectangle tool to draw and position it correctly.

最后,在F.Courtyard图层上添加另一个正方形,使其略微超出刚刚创建的丝网印刷图层正方形的范围。您可以通过将网格间距设置为非常小的值(例如 0.01 毫米),然后在远离丝网印刷矩形的位置绘制一个矩形来实现这一点,以避免网格对齐。

Finally, add another square on the F.Courtyard layer that sits just slightly outside the silkscreen layer square you just created. You can achieve this by setting the grid to a very small spacing value such as 0.01mm and then drawing a rectangle away from the silkscreen rectangle to avoid it snapping.

新建一个边长为 19.4 毫米的正方形,然后可以使用 M 键将其移动到指定位置。这个位于前院层的新正方形为“DRC”(设计规则检查器)提供了一项服务,其边界不应重叠。这意味着,在后续流程中,如果某个元件发生重叠,运行 DRC 时,PCB 上的这条边界将被标记为问题。

Make the new square 19.4mm and then you can use the M key to move the square into position. This new square in the front courtyard layer provides a service called the ‘DRC’ or ‘Design Rules Checker’ with a boundary that shouldn’t be overlapped. This means that later in the process, if a component is overlapping, this boundary on the PCB when you run the DRC will be highlighted as an issue.

板载USB接口

USB On Board

现在您几乎拥有制作 Stamp 和 BMP280 板所需的一切!您可能已经注意到主图中 PCB 板上直接有一个 USB 边缘连接器。这是一种无需添加任何额外元件即可添加 USB 接口的简便方法,不过您需要在该区域(1.6mm 厚的 PCB 板背面)添加大约 1mm 的材料,才能使 USB 连接器能够正确安装。这突出了使用其他已获得适当授权的 KiCad 项目中的库和元件的另一种方法。USB Armory 在其早期 Mk1 版本中就采用了这种 PCB 板边缘 USB 连接器的设计方案。

You’ve now got nearly everything you need to make the Stamp and BMP280 board! You might have noticed a USB edge connector directly on the PCB in the main image. This is a cheap and cheerful approach to adding USB without adding any extra components, although you will need to add around 1mm of material to the back of the 1.6mm thick PCB in this area to actually make the USB connector fit. This highlights another way of using libraries and components from other, suitably licensed, KiCad projects. The USB Armory, which, in an early Mk1 version, used the USB edge connector on PCB approach.

USB Armory 是一个开源项目——您可以从这里下载项目仓库:hsmag.cc/USBArmory。下载完成后,解压缩文件夹,然后使用 KiCad 导航到 hardware 文件夹,标记一,并打开armory.kicad_pro文件。打开后,切换到 PCB 编辑器,选择USB 边缘连接器封装,然后按 E 键。在“封装属性”窗口中,单击“编辑封装”按钮。这应该会在封装编辑器中打开该封装。您可能会收到一条警告,提示该封装是用早期版本的 KiCad 创建的,但保存封装后即可消除此警告。

USB Armory is an open source project — you can download the project repository here: hsmag.cc/USBArmory. Once downloaded, unzip the folder and use KiCad to navigate to the hardware folder, then mark-one, and then open the file armory.kicad_pro. Once open, move to the PCB Editor and select the USB edge connector footprint and press E. In the Footprint Properties window, click the Edit Footprint button. This should open the footprint in the Footprint Editor. You might get a warning that the footprint was made with an earlier version of KiCad, but saving the footprint in the editor should clear this warning.

您应该看到封装焊盘和丝印线(同时也是PCB板边缘切割的参考线)现在已在封装编辑器中打开。编辑器顶部会显示一条警告,提示您当前仅编辑当前项目中的封装。您可以使用“文件”菜单,然后选择“另存为”来重命名此封装并将其保存到您之前创建的自定义库中。由于该库是在全局表中创建的,因此现在可以在任何项目中使用此USB边缘连接器封装。您应该对版本进行一些编辑,更清晰地标记焊盘,然后将其保存到库中。记下每个焊盘的连接方式后,您应该重复之前的步骤,在库中创建一个自定义符号来表示原理图中的USB连接器。

You should see that the footprints pads and the silkscreen line (which doubles as a guide for the edge of the PCB board cut out) are now opened in the Footprint Editor. Across the top of the editor you should see a warning that you are currently only editing the footprint within the current project. You can use File then Save As to rename and save this footprint into your custom library that you created earlier. As that library is created on the Global table, this USB edge connector footprint is now available to use in any project. You should edit your version a little, labelling the pads more clearly, and save it to your library. Making a note of each pad's connectivity, you should repeat the earlier approach to create a custom symbol in the library to represent the USB connector in the schematic.

元件已经创建完成。现在你应该能够像之前一样,将它们放置在原理图中,分配封装,然后导入到PCB中。

That’s the components created. You should now be able to place them in your schematic, assign the footprint and then bring them into a PCB just as you have done previously.

撒网

Casting a net

您可以在图 3-7中看到完整的电路图。在这个电路中,连接点比您之前使用过的要多。虽然您可以像以前那样连接,但结果会非常复杂。为了使电路更清晰易读,您可以使用网络(也称为“网”)。网络是指为每个连接点命名。连接到特定名称网络的每个连接点都被视为彼此连接。

You can see the complete schematic in Figure 3-7. In this circuit, there are more connections than you’ve used previously. While you could wire them up as you did before, the result would be quite a tangled web. To make things a little more readable, you can use networks, aka nets. This is where you give a name to a connection. Every connection to a particularly named net will be considered connected to each other.

图 3-7:我们像在前一个项目中一样,同时使用了自定义连接器符号和通用连接器符号。

要将项目添加到特定网络,您需要添加标签并将其连接到该网络。单击“添加网络标签 (L)”工具图标。然后在原理图中单击,此时将出现“标签属性”对话框。在对话框中,您只需输入网络标签的名称,例如,输入字母“L” A。您可以更改字体和大小,满意后,单击“确定”按钮,即可将A标签放置到原理图中。

To add an item to a particular net, you need to add a label and connect it to this. Click the Add a net label (L) tool icon. You then click in the schematic and the Label Properties dialogue will appear. Into this you simply type the name of your net label, so, for example, type the letter A. You can change the font and size, but when you are happy, click the OK button and you can now place your A label into the schematic.

请注意它有一个小的方形连接器。然后,您可以使用“添加导线”A工具,像连接其他元件一样将导线连接到标签上。您可以使用相同的方法重新创建另一个标签,将其连接到无线连接的另一端,或者您可以复制并粘贴原始网络标签。如果您有更复杂的描述性网络标签名称,最好使用复制粘贴(如果您创建的网络标签拼写错误,它将无法连接,并且您可能需要一段时间才能发现错误)。在这个简单的 H 桥示例中,您实际上不需要使用此技巧,但在下一章中,对于更复杂的设计,使用网络标签确实有助于保持原理图的简洁性和可读性。A

Notice that it has a small square connector. You can then connect a wire to the A label as you would to any other component using the Add a wire tool. You can recreate another A label using the same method to attach to the other end of your wireless connection, or you can copy and paste the original net label. If you have more complex descriptive net label names, it can be a good idea to use copy and paste (if you create a net label with a spelling mistake, it will not connect and may take you a while to discover the error). In this simple H-bridge example, you don’t really need to use this technique but, in the next chapter with a more complex design, using net labels can really help to keep a schematic cleaner and more readable.

将原理图导入PCB时,连接到同一网络的任何线路都会通过杂乱无章的线路连接起来。

When you import the schematic into the PCB, any connections to the same net will be connected by lines in the rats nest.

完成原理图后,就可以将所有内容导入到PCB设计中。但是,在开始放置元件之前,需要先创建电路板轮廓。

Once you’ve made your schematic, you can import everything into a PCB. However, before you get started placing components, you need to create the board outline.

开辟一条道路

Carving a path

要创建电路板轮廓,您无需使用 PCB 编辑器中的图形工具,而是导入在免费开源软件 Inkscape 中绘制的轮廓(图 3-8。虽然 KiCad 自带的工具非常出色,但在设计图形组件时,Inkscape 也具有一些优势。在本示例项目中,我们在 Inkscape 中绘制了一个简单的电路板轮廓对象,将其保存为 SVG 文件,然后将其导入 KiCad。

To create the board outline, you won’t use the graphical tools in the PCB Editor but, rather, import an outline drawn in the free and open source Inkscape application (Figure 3-8). Whilst the included KiCad tools are excellent, Inkscape can offer some advantages when designing graphic components. For the example project, we drew a simple outline object for the board in Inkscape, saved it as an SVG file, and then imported it into KiCad.

图 3-8:使用 Inkscape 创建 PCB 边缘切割几何形状的精确图形

为此,请单击“文件”,然后从下拉菜单中选择“导入”>“图形…” 。在“导入矢量图形文件”对话框中,您可以导航到该文件并选择要导入的工作图层。将图形图层设置为“Edge.Cuts”时,请注意您还可以设置“导入比例”值。在本例中,我们在 Inkscape 中已将电路板轮廓设计为正确的尺寸,因此将导入比例保留为 1.00。但是,如果您要将尺寸过大的图形或徽标(例如 HackSpace 徽标)导入到丝印图层,则此功能非常有用。我们在 Inkscape 中将其反转,然后将其导入到背面的丝印图层。

To do this, click File and then select Import > Graphics… from the drop-down menus. In the Import Vector Graphics File dialogue, you can navigate to the file and select the working layer to import to. Setting the graphic layer as Edge.Cuts, notice that you can also set an Import Scale value. In this instance we designed the board outline to be the correct size in Inkscape, so leave the import scale at 1.00. This function is useful, however, if you have an oversized graphic or logo to import to a silkscreen layer, like the HackSpace logo, we’ve reversed in Inkscape and then imported it onto the back silkscreen layer.

在区域

In the zone

最后,我们在这个电路板上使用的另一种技术是创建与网络标签相连的铜箔覆盖区。这是一种自动连接公共连接组的绝佳方法。例如,许多PCB都会有很多连接到GND网络的连接,因此您可以将一层(或一层的一部分)专门用于此网络,并简单地用铜箔覆盖它(图3-9)。

Finally, another technique that we used on this board is to create flooded copper zones attached to a net label. This is an excellent way of automatically connecting groups of common connections. For example, many PCBs will have lots of connections to the GND net, so you can dedicate one layer (or part of one layer) to this net and simply cover it with copper (Figure 3-9).

图 3-9:将电路板加载到位,连接所有 GND 连接焊盘

您可以创建包含许多不同连接方式的填充区域的复杂系统,但在这个项目中,您只在正面铜箔表面使用了一个填充区域,该区域连接了所有接地焊盘。要实现这一点,在电路板布局完成后,使用“添加填充区域”工具。选择此工具,然后单击以在电路板设计上绘制填充区域,确保您位于正确的图层上。此时将出现一个对话框,您可以从列表中选择网络连接,因此您应该选择GND图 3-10)。将所有其他设置保留为默认值,在电路板上绘制一个矩形。不必过于担心精度,因为填充区域只会出现在切割边缘的几何形状内。绘制矩形的三个顶点后,您可以右键单击并从下拉菜单中选择“闭合轮廓” 。现在,矩形(或您绘制的其他形状)应该会被填充,您应该可以看到所有先前断开的GND焊盘现在都已连接。

You can create complex systems with lots of different flooded areas with differing connectivity, but in this project you have just used one flood on the front copper surface that connects all pads attached to ground. To do this, once the board is laid out, use the Add a filled zone tool. Select this tool, then click to start drawing a fill area over your board design, ensuring you are on the correct layer. A dialogue appears and you can select the net connection from the list, so you should select GND (Figure 3-10). Leaving all the other settings at the default values, draw a rectangle over the board. Don’t worry too much about accuracy as the flood will only appear inside the edge-cut geometry. Drawing three points of your rectangle you can then right-click and select Close outline from the drop-down menu. The rectangle (or other shape you drew) should now flood, and you should see that all the previously disconnected GND pads are now connected.

图 3-10:选择浸没铜区将连接的网络

虽然填充区域连接了整个GND网络,但您仍然需要手动连接其余部分。在之前的PCB上,由于结构简单,不会出现线路交叉,因此只需使用PCB的一面即可。然而,这次的情况要复杂一些。PCB几乎总是不止一层。对于业余爱好者来说,两层比较常见,但对于复杂的设计,您可以使用四层甚至更多层。默认情况下,PCB编辑器有两层:正面和背面。您可以通过单击右侧窗格中的“B.Cu”来选择背面层。现在,当您绘制线条时,它将位于PCB的背面,并且在PCB编辑器中将显示为不同的颜色(蓝色)。

While the filled zone connects the entire GND net, you still have to wire the rest of it up manually. On the previous PCB, you could get away with just using a single side of the PCB because it was simple enough not to lead to any crossing wires. However, this is a bit more complex. PCBs almost always have more than one layer. Two is common for hobbyists, but you can go to 4 or even more for complex designs. By default, the PCB Editor has two layers, front and back. You can select the back layer by clicking on B.Cu in the right-hand pane. Now, when you draw a line, it will be on the back of the PCB, and will appear in a different colour (blue) in the PCB Editor.

在PCB板的两面都预留导线固然很好,但如何连接这些导线呢?PCB板上的许多元件都是通孔元件,它们可以贯穿整个PCB板,并且可以从两侧连接。你还可以添加“过孔”——这些小孔贯穿并连接PCB板的正反两层。

It’s all well and good having wires on both sides of the PCB, but how do you join them? Many of the components on the PCB are through-hole, and these create a link through the PCB and can be connected on either side. You can also add ‘vias’ — these are small holes that go through and link the front and back layers of the PCB.

要添加过孔,请单击“过孔”工具,然后单击PCB上所需的位置。之后,您可以将导线连接到PCB两侧的过孔上,它们就会连接起来。

To add a via, click on the Vias tool, then click at the place on the PCB where you want it. You can then connect wires to it on either side of the PCB and they’ll be connected.

您可能会发现需要在已填充区域的中心放置轨道。如果遇到这种情况,这不成问题,您只需使用快捷键B重新计算已填充区域,系统就会跳过洪水区域。但这也可能导致系统遗漏已填充区域网络中本应存在的连接;在这种情况下,您可能需要手动连接。

You might find that you need to place a track through the middle of your filled zone. If you do, this isn’t a problem, you just need to use the B hotkey to recalculate the filled zone and it will skip out the area of the flood. It’s possible this will mean that it misses a connection that should be in the net for the filled area; in this case, you may need to connect it in manually.

您可以查看我们最终的项目文件,了解我们如何放置组件和连接线路,但实现方法有很多种,您也可以选择不同的方法。

You can take a look at the finished project file for our solution to placing the components and wiring it up, but there are many ways of doing it and you may choose to do it differently.

第四章

Chapter 4

使用PCB组装服务

Using a PCB assembly service

创建可以由知名PCBA公司完全组装的项目

Create projects that can be fully assembled by popular PCBA companies

前三章我们讲了很多内容。如果你认真学习了所有章节,现在应该能够设计简单的电路板了。接下来,我们要做一些更复杂的设计。我们将从一个小型电机驱动器开始,逐步构建一个基于RP2040微控制器的开发板。

We covered a lot in the previous three chapters. If you worked through them all, you’ll be at a point where you can create simple board designs. Now, you’re going to do something a little more complex. You’ll start with a small motor driver and build up to a development board based on the RP2040 microcontroller.

图 4-1: PCBA 服务成功组装的 PCB 设计

RP2040芯片本身采用56引脚四方扁平无引脚(QFN-56)封装,虽然可以使用回流焊或热板焊接等方法在家自行焊接,但这既困难又耗时。为了避免这种情况,您需要使用PCB组装(PCBA)服务。

The RP2040 chip itself comes in a Quad Flat No-leads 56 pin (QFN-56) package, and while that can be soldered at home using reflow or hotplate soldering techniques, that’s difficult and time consuming. To avoid this, you are going to use a PCB assembly (PCBA) service.

制作基于 RP2040 的电路板有很多需要考虑的地方,因此在本文中,您将准备一个更简单的设计进行制造,以帮助您学习如何使用 PCBA。

There’s a lot to look at in making an RP2040-based board, so in this article, you’ll prepare a simpler design for manufacture to help you learn how to work with a PCBA.

为PCBA进行设计会增加复杂性,因为您需要创建大量文件、定义PCB设计,并选择元件并将其放置在电路板上。这些元件必须提供给PCB组装厂,这又增加了复杂性。最初几次进行此流程时,与在家自行组装PCB相比,工作量似乎很大,但好处是您可以获得完整的电路板——无需焊接——随着PCB尺寸和复杂性的增加,这将显著节省时间。

Designing for PCBA adds complexity in that you have to create numerous files, define the PCB design, and choose and place components on the board. These components must be available to the PCB assembly house, which again adds complexity. The first few times you do this process, it’ll seem like a lot of work compared to simply creating a PCB to assemble at home, but the pay-off is that you get complete boards — no soldering necessary — and this is a significant time-saver as your PCBs become larger and more complex.

PCB组装

在前面的章节中,我们推荐了 OSH Park 作为 PCB 制造商——他们接受 KiCad PCB 文件上传,操作非常便捷。如果您想使用 PCBA 服务,则可能需要提供Gerber 文件和包含钻孔信息的文件。

In earlier chapters, we suggested OSH Park for manufacturing PCBs — they make it easy by accepting KiCad PCB file uploads. If you want to use a PCBA service, it’s likely you will need to plot Gerber files and files containing drilling information.

Gerber 文件和钻孔文件有一些变量,您的加工服务商应该会提供一些关于他们所需文件的信息。例如,JLCPCB 有一个页面 ( hsmag.cc/gerberdrillkicad ) 列出了他们服务所需的 KiCad Gerber 绘图仪设置。虽然其中的截图来自 KiCad 5.19 版本,略显过时,但您可以在 KiCad 的“绘图”对话框中找到所有相同的选项。要访问“绘图”对话框,请在 PCB 编辑器中单击“文件”>“加工输出”>“Gerber” 。

Gerber and drill files have some variables, and your fabrication service should give you some information regarding what they need. For example, JLCPCB has a page (hsmag.cc/gerberdrillkicad) that outlines the KiCad Gerber plotter settings that their service needs. It’s a little out of date in that the screenshots are from KiCad 5.19, but you can find all the same options on the KiCad Plot dialogue. To access the latter, you click File > Fabrication Outputs > Gerbers from the PCB Editor.

绘制 Gerber 文件会为 PCB 设计的不同层生成一系列文件,因此请务必在“绘制”对话框顶部创建一个文件夹来存放 Gerber 文件,否则它们最终都会混杂在项目的根文件夹中。绘制完 Gerber 文件后,您还可以从“绘制”对话框创建钻孔文件。单击“生成钻孔文件”按钮将打开钻孔文件对话框。对于 JLCPCB,请将钻孔文件放在与 Gerber 文件相同的文件夹中,最后将该文件夹压缩成 zip 文件并上传到 JLCPCB。

Plotting Gerbers creates a bunch of files for different layers of your PCB design, so make sure that you create a folder for your Gerber files at the top of the Plot dialogue, or else they all end up mixed into the main root folder of your project. You can also create the drill file from the Plot dialogue after you have plotted your Gerber files. Clicking the Generate drill files button will launch a drill file dialogue. For JLCPCB, place your drill file into the same folder as you did your Gerber files and, finally, compress this folder into a zip file for upload to JLCPCB.

其他PCB制造商会提供他们所需的文件格式指南。如果您上传的文件无法正常工作,也不用太担心:系统会提示错误,您可以随时联系在线客服寻求帮助或指导。

Other PCB fabrication houses will have guidance on what format they require. Don’t worry too much if you upload something that doesn’t work: it will give you an error and you can always ask the online chat service for help or guidance.

我们将在第 9 章“寻找 PCB 制造商”中更深入地了解不同的制造厂及其要求。

We’ll look a bit more deeply at different fabrication houses and their requirements in Chapter 9, Finding a PCB manufacturer.

因此,为了探索PCBA服务,我们使用KiCad设计了一个小型电机驱动电路(H桥),该电路使用了四个N沟道MOSFET。我们不会详细介绍电路板设计,因为我们在本书前面的章节中已经介绍过这种方法。

So, for this exploration of PCBA services, we’ve laid out a small design in KiCad for a motor driver circuit (H-bridge) using four N-channel MOSFETs. We’re not going to step through the board design, because we covered the approach in earlier parts of the book.

您可以直接从hsmag.cc/kicad_book_files获取项目文件。该文件包含完整的原理图和 PCB 文件。项目位于eg/ch04子目录中。您可以跟随本章了解我们为自动装配所做的准备工作。

You can grab the project directly from hsmag.cc/kicad_book_files. That has the complete schematic and PCB. The project is in the eg/ch04 subdirectory. You can follow along in this chapter to find out what we did to prepare them for automatic assembly.

您将使用广受欢迎且价格合理的 JLCPCB 组装服务来制造和组装电路板。这意味着您需要考虑电路板上要使用的元件,因为每个元件都必须在 JLCPCB 的元件库中可用。首先,请访问 JLCPCB 网站 ( jlcpcb.com ) 并注册一个帐户。

You’re going to use the popular and reasonably affordable JLCPCB assembly service to manufacture and assemble the boards. This means that you need to consider what parts you are going to use on the board, as each part needs to be available in the JLCPCB parts library. The first thing to do is to head over to the JLCPCB website (jlcpcb.com) and register for an account.

您可以使用搜索功能和筛选器浏览 JLCPCB 元件库 ( jlcpcb.com/parts ),查看元件的价格和库存情况。您还可以提前购买元件,将它们存储在您自己的虚拟仓库中,以便将来在电路板设计中使用。对于项目关键元件而言,这项功能非常实用,因为没有什么比完成一个复杂的设计后却发现元件缺货且可能要等上一段时间更令人恼火的了。

You can explore the JLCPCB parts library (jlcpcb.com/parts) using the search function and filters — you’ll see parts’ cost and availability. You can also advance-purchase components so that they are held in your own virtual warehouse ready to be used on your board designs in the future. This can be a very useful feature for parts critical to your project as there are few things more annoying that completing a tricky design only to find out that the parts are out of stock and may be for some time.

需要注意的是,可用的元器件分为两大类:“基础元件”和“扩展元件”。基础元件将按标价添加到您的电路板上。例如,如果您添加五个单价为 0.07 美元的基础电阻,则每个电路板的成本为 0.35 美元。但是,如果该元件被列为扩展元件,则其单价不变,但需要一次性支付 3 美元的设置费,因为该元件需要从仓库手动取出并装入贴片机。

One thing of note is that available components fall into two distinct groupings: ‘basic parts’ and ‘extended parts’. Basic parts will be added to your board at the price listed. So, if you are adding five basic part resistors at 0.07 dollars each, then they will cost 0.35 per board. However, if that part was listed as an extended part, then that part will still cost the same unit price, but there will be a one-time $3 setup cost of including that part in your project, as the part will have to be manually retrieved from storage and loaded into the pick-and-place machines.

浏览 JLCPCB 元件库时,如果您发现可能用到的元件,请记下其元件编号——这些编号通常以字母“C”开头,并列在元件主页面上。以小型 H 桥板为例,您只需要 JLCPCB 添加 SMD 元件,因此请选择一些 10kΩ 电阻(元件编号C49122)和四个 MOSFET(AO3400 芯片,元件编号C20917)(参见图 4-2)。

As you peruse the JLCPCB parts library, if you spot a component that you are likely to use, make a note of the part number — these usually start with the letter ‘C’ and are listed on the main component landing page. For the small H-bridge board example, you’ll only be interested in having JLCPCB add the SMD components, so choose some 10kΩ resistors (part number C49122), and the four MOSFETs (AO3400 chips, part number C20917) (see Figure 4-2).

图 4-2:在 JLCPCB 元件库中搜索元件

您需要在符号属性中添加这些详细信息到额外的字段中,以便稍后在生成物料清单 (BOM) 时能够识别这些特定组件。(如果要让 JLCPCB 在设计中忽略通孔组件,请不要将此额外字段添加到其原理图符号中。这样,它们就不会包含在装配过程中。)

You need to add these details to an extra field in Symbol Properties so that later, when you generate a bill of materials (BOM), these specific components will be identified. (To have JLCPCB ignore the through-hole components in a design, don’t add this extra field to their schematic symbols. That way, they won’t be included in the assembly process.)

要添加这些详细信息,请在原理图编辑器中选中一个元件,然后按E键打开“符号属性”对话框。单击“+”按钮(鼠标悬停在其上时会显示“添加字段”字样)(图 4-3)。此时应该会出现一个新的字段行。在“名称”列中,您需要将此字段标记为LCSC(LCSC Electronics 是一家元件供应商,也是 JLCPCB 的母公司),然后在“值”列中,添加您为该元件查找到的 CXXXXX 编号。

To add these details, highlight a component in the Schematic Editor and press the E key to open the Symbol Properties dialogue. Click the + button, which is labelled Add field when you hover over it (Figure 4-3). You should see a new field line appear. In the Name column, you need to label this field LCSC, (LCSC Electronics is a parts supplier and the parent company of JLCPCB) and then in the Value column, add the CXXXXX number you researched for that component.

图 4-3:在符号属性中添加额外的 LCSC 字段可以创建正确的物料清单 (BOM)。

您需要对每个希望 JLCPCB 添加到电路板上的元件执行此操作;您不能只在一个 10kΩ 电阻上添加此字段,就期望它为其他元件添加相同的元件。对于小型项目(例如本例),您可以手动为每个原理图符号执行此操作。对于大型项目,另一种方法是在库级别编辑符号,或者将符号复制到自定义库中,并在符号级别填充 LCSC 字段和编号。这意味着,每当您将该自定义符号放置在原理图中时,您都已准备好正确的 LCSC 元件编号,可用于物料清单 (BOM)。在创建 BOM 之前,您仍然必须像在任何 PCB 设计中一样,为符号分配封装。

You need to do this for every component you expect JLCPCB to add to your board; you can’t just add this field to one 10kΩ resistor and expect it to add the same part for the others. For small projects, such as this example, you can do this manually for each schematic symbol. An alternate approach for larger projects is that you can edit the symbol at the library level or copy the symbol to a custom library with the LCSC field and number populated at the symbol level. This means that whenever you place that custom symbol in the schematic, you have the correct LCSC part number ready for the Bill Of Materials (BOM). Before creating the BOM, you still must assign the footprints to the symbols as you would for any PCB design.

确保您已进入原理图编辑器,然后单击“生成物料清单”图标。在出现的对话框中,单击左上角的“编辑”选项卡。现在您应该会看到类似于图 4-4 的内容,其中列出了您的项目组件及其详细信息。在对话框的左侧,您可以看到一个可勾选的字段列表,您可以启用或禁用这些字段。对于用于组装的 JLCPCB 物料清单,每个组件需要四个字段:注释标识符封装LCSC 本书中的大多数项目都为每个组件符号添加了一个用于存储 LCSC 编号的自定义字段;请注意,此自定义字段包含在可选字段中。如果您取消选中列表中除“值”“参考”“封装”LCSC之外的所有字段,您应该会看到类似于图 4-5 的预览电子表格。

Make sure you’re in the Schematic Editor, then then click the Generate a Bill of Materials icon. In the dialogue that appears, click the Edit option tab in the upper left. You should now see something similar to Figure 4-4 with your project components and details listed. In the left-hand side of the dialogue you can see a ticklist of visible fields which you can turn on and off. For a JLCPCB BOM for assembly you will want four fields for each component: you will need a Comment, a Designator, a Footprint, and an LCSC for each component you wish to place. In most of the projects in this book, we’ve added a custom field to each component symbol for the LCSC numbers; notice that this custom field is included in the selectable field. If you uncheck everything from the list apart from Value, Reference, Footprint, and LCSC, you should see a preview spreadsheet like Figure 4-5.

图 4-4:新 KiCad 8 BOM 编辑器窗口中的“编辑”选项卡。
图 4-5:物料清单中包含字段数据的正确列。

您的列顺序可能与 JLCPCB 要求的布局不符。如果是这样,您可以点击对话框右侧的列标题/标签,并将其拖动到其他位置。如果列从左到右的顺序是“值”“参考”“封装”“LCSC”,则符合 JLCPCB 的物料清单格式。此外,列字段标题可能与 JLCPCB 的要求不完全一致。在对话框左侧,点击“标签”列以重命名字段标题。JLCPCB 从左到右要求依次为“注释”“标识符”、“封装”“LCSC ”,因此您必须进行相应的调整。

It’s likely that your column order doesn’t match JLCPCB’s required layout. If so, you can click the column title/label in the right-hand side of the dialogue and drag it to another position. If the columns are ordered Value, Reference, Footprint, and LCSC from left to right, then this matches the JLCPCB BOM format. Finally, the column field titles won’t quite match the JLCPCB requirements. In the left-hand side of the dialogue, click on the Label column to rename a field title. From left to right, JLCPCB requires a Comment, a Designator, a Footprint, and an LCSC — so you must make those adjustments.

一切确认无误后,您可以返回左侧对话框的“导出”选项卡,设置文件名,并将文件类型设置为 CSV,然后单击“导出”按钮。之后,单击“应用”、“保存原理图”和“继续”,以确保此 BOM 格式保留在此项目中。

Once everything looks correct, you can click back over to the Export tab in the left-hand dialogue and set a filename and set the filetype to CSV and click the Export button. Then, click Apply, Save Schematic and Continue to make sure this BOM format remains in this project.

如果您需要,这里有关于 JLCPCB 所需的 BOM 格式的详细信息:hsmag.cc/jlcbom,大多数 PCB 和组装服务商也会有类似的页面,详细介绍所需的 BOM 和其他文件格式。

In case you need it there are details about the BOM format required by JLCPCB here hsmag.cc/jlcbom and most PCB and assembly service will have similar pages detailing the BOM and other file formats needed.

精准定位

Precise Placement

PCBA 的最后一步是生成封装位置文件,也称为质心文件。与 BOM 文件类似,它本质上是一个电子表格,其中包含每个放置元件的详细信息,包括坐标和旋转角度。

The final piece of the PCBA puzzle is to generate a footprint position file, also referred to as a centroid file. Like the BOM file, this is essentially a spreadsheet which contains details of each placed component, showing both coordinates and the rotational angle of the part.

要生成此信息,请在 PCB 编辑器中选择“文件”>“制造输出”>“元件布局”。确保您的设置与图 4-6中所示的对话框一致。请注意,如果您的项目包含您希望 JLCPCB 包含的通孔元件,则需要取消选中“仅包含 SMD 封装”选项,并在物料清单 (BOM) 中包含这些通孔元件的 LCSC 编号。

To generate this, in the PCB Editor, select File > Fabrication Outputs > Component Placement. Make sure that your settings match the dialogue box shown in Figure 4-6. Note that if your project contains through-hole components that you want JLCPCB to include, you need to uncheck the Include only SMD footprints option and include the LCSC numbers for those through-hole parts in the BOM.

请勿将之前生成的元件封装 POS 文件或 BOM 文件包含在 Gerber 文件的压缩包中,因为它们需要单独上传。准备就绪后,点击“生成位置文件”按钮。请注意,这将生成两个 POS 文件:一个用于上层,一个用于下层。由于设计是单面的,您只需要上传上层文件即可。

Don’t include this component footprint POS file or the BOM file you generated earlier inside the zip file of Gerbers, as they are uploaded separately. Once you are ready, click the Generate Position File button. Notice that this will generate two POS files: one for the upper layer and one for the lower layer. As the design is single-sided, you are only interested in — and later, only need to upload — the upper layer file.

生成上层 POS 文件后,您需要对电子表格的列标题进行一些修改,才能使其在 JLCPCB 中正常工作。请在电子表格程序中打开生成的文件。您可以使用 LibreOffice Calc、Microsoft Excel 或 Google Docs。

With the upper layer POS file generated, you need to make a few alterations to the spreadsheet column header titles for it to work properly for JLCPCB. Open the file you have generated in your spreadsheet program. You can use LibreOffice Calc, Microsoft Excel, or Google Docs.

图 4-6:生成放置文件对话框

接下来,进行以下更改:将第一列的标题“Ref”更改为“Designator”将“PosX”和“ PosY”分别更改为“Mid X”“Mid Y”将“Rot”更改为“Rotation ” ;最后,将“Side”更改为“Layer”图 4-7)。保存修改后的 POS 文件——现在您已拥有上传到 JLCPCB 服务所需的一切。

Next, make the following changes: change the title of the first column, Ref, to Designator; PosX and PosY to Mid X and Mid Y; Rot to Rotation, and finally, Side to Layer (Figure 4-7). Save the POS file with these alterations — you now have everything you need to upload to the JLCPCB service.

一切准备就绪后,请访问 JLCPCB 网站。点击“标准 PCB/PCBA”选项卡上传 Gerber zip 文件。上传完成后,您应该会在预览窗口中看到电路板正反两面的渲染图(图 4-8)。您可以在此页面上更改电路板类型、材料、厚度等参数。不过,除了将电路板颜色更改为黄色(这纯粹是为了美观——我们想要比标准绿色更亮一些的颜色)之外,我们保留了所有默认设置。

With everything ready, head to the JLCPCB website. Click on the Standard PCB/PCBA tab to upload the Gerber zip file. After a short upload, you should see a render of the upper and lower sides of your board in the preview window (Figure 4-8). You can make changes to the board type, material, thickness, and more on this initial page. However, apart from changing the colour of the board to yellow (this is purely decorative — we wanted something a bit brighter than the standard green), we left everything at the default setting.

图 4-7:使用 LibreCalc 编辑生成的位置文件列标题
图 4-8:如果 Gerber ZIP 文件上传成功,您将看到电路板的第一张预览图(之后还会有更多预览图)。

在页面底部,您可以点击按钮添加/展开PCBA服务。如图4-9所示,我们选择仅组装顶面(因为元件只位于这一面)。根据您选择的是经济型组装还是标准型组装,您需要选中“边缘导轨/基准标记”“工具孔”由JLCPCB添加)选项。这表示对于这些非常小的电路板,JLCPCB服务将创建所需的面板布局。选择所有选项后,点击“下一步”

At the bottom of the page, you can click a button to add/expand the PCBA services. In Figure 4-9, you can see that we have opted to have the top side assembled only (as you only have components on this side). Depending on whether you’ve selected Economic or Standard Assembly, you’ll want to highlight select either Edge Rails/Fiducials or Tooling holes as Added by JLCPCB option highlighted. This indicates that for these very small boards, JLCPCB services will create any needed panel layouts. With all that selected, click Next.

您将看到由 Gerber 文件上传生成的 PCB 布局的更大预览图。请仔细检查,然后单击“下一步”进入下一个选项卡。预览图将如图4-9所示。单击“添加 BOM 文件”按钮,上传您之前创建的 BOM 文件;然后单击“添加 CPL 文件”按钮,上传您之前创建和编辑的顶层 CSV 位置文件。单击“下一步”,这些文件将被上传和处理,这可能需要几分钟时间,之后您应该会看到电路板和元件布局的渲染图。

You’ll get another larger preview of the PCB layout generated from the Gerber uploads. Check it carefully and then click Next to move to the next tab. This will look like Figure 4-9. Click the Add BOM File button and upload the BOM file you created earlier, then click the Add CPL File button and upload the top layer CSV positional file you made and edited earlier. Clicking Next, these will be uploaded and processed, which may take a few minutes, and you should see a render with the board and the components placed.

图 4-9: PCBA 服务的初步选择

让我转圈

Spin me around

通常情况下,此时您会发现元件在封装上的旋转角度不正确。有两种方法可以纠正这个问题。如果您的元件角度是标准的,您可以点击渲染图像中的元件进行高亮显示,然后在高亮显示后,使用 JLCPCB 网页上 PCB 渲染图上方的旋转工具(图 4-10)。您可以反复调整,直到设计看起来正确为止。点击“下一步”将保存这些方向设置,并跳转到“添加到购物车”订购页面。虽然这种方法可行,但另一种选择是打开您创建并上传的位置文件,然后编辑渲染图中显示错误的元件的旋转值。根据我们的经验,两种方法都可以,JLCPCB 的工程师通常会询问元件是否正确放置在封装上(尽管最好不要完全依赖这一点)。

Often, at this point, you will find that components are not rotated correctly on the footprints. There are two ways to correct this, if your components are at standard angles, you can click to highlight a component in the render image and, when they are highlighted, use the rotation tools above the PCB render in the JLCPCB web page (Figure 4-10). You can continue to do this until your design looks correct. Clicking Next will save these orientations and take you to the Add to Basket ordering page. Whilst this is a fine approach, another option is to open the positional file you created and uploaded and then edit the rotational value of the components that have appeared incorrectly in the render. In our experience, either way is fine, and the JLCPCB engineers will usually question if a component isn’t sitting on a footprint correctly (though it’s best not to rely on this).

图 4-10:您可以在 JLCPCB 订购流程中通过浏览器校正封装旋转位置,也可以离线编辑位置文件以创建正确的值。

您只需将订单添加到购物车并付款即可。订单确认付款后,您将定期收到订单列表的更新信息。如果设计较为复杂,建议您在下单后四到六个工作小时登录您的账户,查看订单历史记录详情中关于组件布局的分析。

All that’s left to do is to add the order to your shopping basket and pay. Once the order is confirmed and paid, you get regular updates on the order listing and, if it’s a complex design, it’s worth checking back into your account four to six working hours after placing the order to check the analysis regarding component placing in the order history details.

所有部件都订购完毕后,您只需等待即可。具体时间不固定,但通常很快。我们用 KiCad 设计了这个简单的 H 桥电机驱动器,八天后就拿到了组装好的 PCB 板(图 4-1,本章前面已展示)。

Once everything is ordered, all you have to do is wait. The exact times vary, but it’s often quite quick. We started this simple H-bridge motor driver design in KiCad and had the assembled PCBs (Figure 4-1, shown earlier in this chapter) in our hand eight days later.

第五章

Chapter 5

设计RP2040板

Designing an RP2040 board

为您定制专属的微控制器板

Get your custom microcontroller board made for you

在前几章中,您学习了从原理图到电路板布局的PCB板制作基础知识,并在此过程中掌握了各种技能和方法。在此基础上,您进一步探索了如何使用KiCad和PCB组装(PCBA)服务,不仅可以制造PCB,还可以将元件安装到PCB上,并以完全组装好的形式交付给您(图5-1)。

In the previous chapters, you worked through the basics of making PCB boards from schematic to board layout, and you learned a variety of skills and approaches along the way. You built on this by exploring how to use KiCad and a PCB assembly (PCBA) service to not only have the PCB manufactured, but to also be populated with components and supplied to you fully assembled (Figure 5-1).

图 5-1:完全组装且功能齐全的基于 RP2040 的电路板

RP2040 非常适合采用工业级组装方式的 PCB 项目。胆子大的人或许可以尝试在家焊接 QFN 56 封装,但 PCBA 服务能让一切变得简单得多。

RP2040 is a great target for PCB projects that will be assembled using industrial approaches. The bolder amongst us might successfully be able to solder up the QFN 56 package at home, but PCBA makes everything a lot easier.

许多市售的RP2040微控制器板都采用四层或更多层的PCB​​板制造。当然,在KiCad中也可以实现四层板的设计,但对于我们大多数人来说,四层板的调试和故障修复会比较困难。幸运的是,两层板就足以让微控制器运行起来,并实现所需的功能。

Many commercially available boards that use the RP2040 are manufactured using PCBs with four or more layers. Of course, it’s possible to do this in KiCad, but for many of us, four-layer boards can be difficult to debug or correct if something goes wrong. Fortunately, two layers is enough to get a microcontroller running and break out the features you need.

RP2040 发布的同时,也发布了一系列优秀的文档,其中包括一份出人意料地易读的《基于 RP2040 的硬件设计》图 5-2)。这份文档展示了一个基于 RP2040 的极简电路板示例(双层设计),并详细描述了设计的各个方面和注意事项。文档中甚至还提供了一个 KiCad 项目文件。建议您下载并仔细阅读该项目文件(图 5-3)。在本章中,您将复现此电路板设计,但会从一个空白项目开始,而不是使用文档中提供的项目。

When RP2040 was released, so too was a stack of excellent documentation, including the surprisingly readable Hardware design with RP2040 (Figure 5-2). This document shows an example of a minimal RP2040-based board, a two-layer design, and then describes various aspects of the design and considerations. There is even a KiCad project file for the design. It’s a great idea to download the project file and review it (Figure 5-3). In this chapter, you’ll replicate this board design, but you’ll start from a blank project rather than using the one supplied.

图 5-2:树莓派提供的 RP2040 文档及其出色的硬件设计
图 5-3:RP2040 硬件设计文档中还包含一个 KiCad 示例项目。

从零开始意味着您可以更轻松地根据自身需求调整此项目。您还需要对项目进行一些调整,因为目前 JLCPCB 并未提供树莓派示例中使用的一些特定元件。此外,树莓派示例是用早期版本的 KiCad 构建的,并且使用了内部开发的 RP2040 原理图符号。而现在,RP2040 已成为 KiCad 的标准库元件。

Starting from scratch means that it’s easier to adapt this project to your own needs. You’ll also tweak the project because currently, JLCPCB doesn’t supply some of the exact components used on the Raspberry Pi example. Also, the Raspberry Pi example was built in a previous version of KiCad and uses in-house schematic symbols for the RP2040. Since then, the RP2040 has become a standard library component within KiCad.

RP2040原理图符号中的一些连接已经在符号级别预先设定好(例如公共电源引脚连接),因此使用KiCad内置的符号和封装是合理的。尽管如此,本章不会详细介绍电路板设计的每个步骤,因为您在前面的章节中已经学习了基础知识,所以本章将重点介绍RP2040电路板的创建要点。您可以从hsmag.cc/kicad_book_files的eg/ch05子目录中下载本项目的KiCad文件

Some of the connections on the RP2040 schematic symbol are already made at a symbol level (like common power pin connections), so it makes sense to use the built-in KiCad symbols and footprints. With that all said, this chapter won’t step through every stage of designing this board as you’ve learnt the basics in previous chapters, so you’ll learn things that are specific to creating an RP2040 board. You can download the KiCad files for this project from hsmag.cc/kicad_book_files in the eg/ch05 subdirectory.

本章的项目模拟了最小设计示例中的原理图布局和PCB布局。这部分是因为PCB布局已经巧妙地解决了许多布局复杂性问题,但也方便您在构建自己的项目时对这两个项目进行比较。

This chapter’s project emulates both the schematic layout and the PCB layout of the minimal design example. This is partly because the PCB layout has neatly solved a lot of the layout complexity, but it also allows you to compare the two projects as you build your own.

提前规划:组件和布局

Planning ahead: components and footprints

在为 JLCPCB 设计电路时,即使在原理图层面,也需要考虑将要使用的元器件及其封装。对于 RP2040 板,我们希望使用表面贴装的 micro USB-B 插座,其中所有 USB 机箱和接地引脚都位于上层——这意味着它可以作为 SMD 元器件进行组装。因此,除了引脚/插座之外,整个单元将由 JLCPCB 完成组装。

When designing for JLCPCB, even at the schematic level, you need to be thinking about what component and footprint you will be using. For the RP2040 board, we wanted to use a surface-mount micro USB-B socket where all the USB chassis and ground points are on the upper layer — this means it could be assembled as an SMD component. As such, apart from the pin headers/sockets, the units would be fully assembled by JLCPCB.

浏览LCSC元件库(lcsc.com)后,我们选择了C132560元件。JLCPCB经常提供EasyEDA的原理图和封装符号。幸运的是,您可以将其导入KiCad(这是KiCad 8的新功能,因此请确保您使用的是最新版本)。

Looking through the LCSC component library (lcsc.com), we opted for the C132560 component. JLCPCB often supplies schematic and footprint symbols for EasyEDA. Fortunately, you can import this into KiCad (this is a new feature in KiCad 8, so make sure you’re running the most up-to-date version).

要获取这些文件,您需要注册一个 EasyEDA 帐户 ( easyeda.com )。在 JLCPCB 库网站的元件页面上,点击 LCSC 元件库中标有“PCB 封装”或“元件符号”的链接,然后在显示元件符号和封装的弹出窗口下方点击“免费试用”按钮。

To get the files, you’ll need to set up an EasyEDA account (easyeda.com). Click the link in the LCSC component library that says PCB Footprint or Symbol on the component page on the JLCPCB library website, then click the Free Trial button underneath the pop-up window that shows the component symbol and footprint.

设置登录后,您应该会看到一个基于浏览器的 EasyEDA 项目,其中只加载了组件的占位图。

After setting up a login, you should see a browser-based EasyEDA project with just the footprint of the component loaded.

EasyEDA 中有多个选项卡,您应该能够找到并切换两个选项卡,一个显示元件原理图符号,另一个显示元件封装。选中元件选项卡并使其显示在视图中后,单击“文件”>“另存为文档”>“另存为(本地)”图 5-4)。 单击后,应该会下载一个文件类型为 EFOO 的文件。此时,请切换 EasyEDA 中的选项卡,以便查看原理图元件,然后重复相同的“文件”>“另存为文档”>“另存为(本地)”操作,您应该会下载一个文件类型为 ELIBZ 的文件。

There are numerous tabs in EasyEDA and you should be able to find and swap between two tabs, one with the component schematic symbol and one with the component footprint. With the component tab selected and in view, click File > Save As Document Save As (local) (Figure 5-4). When clicked, a file with the filetype EFOO should download. Whilst you are here, swap tabs in EasyEDA so you see the schematic component, then repeat the same File > Save As Document Save As (local) process and you should download a file with the filetype ELIBZ.

图 5-4:使用 EasyEDA 中的本地另存为选项下载原理图符号或元件封装

在 KiCad 的主项目视图中,单击打开封装编辑器。然后,使用“文件”>“导入”>“封装…”并找到下载的 EFOO 文件(图 5-5)。选择该文件,封装将自动导入。接下来,使用“文件”>“另存为”对话框,以常规方式将封装保存到库或自定义库中。

Moving to KiCad in the main project view, click to open the Footprint Editor. Next, use File > Import > Footprint… and navigate to the downloaded EFOO file, Figure 5-5. Select the file and the footprint will be automatically imported. Next, save the footprint to a library or custom library in the usual way using the File > Save As dialogue.

图 5-5:您可以将 EasyEDA 封装导入 KiCad 封装编辑器。

原理图符号的操作步骤相同。打开符号编辑器,使用导入功能导入您下载的 ELIBZ 文件。如果您是第一次打开符号编辑器或封装编辑器,则需要先选择一个工作库才能导入。不过,您可以将导入的项保存到您选择的任何库中。

The process is the same for schematic symbols. Open the Symbol Editor and use the import function to import your downloaded ELIBZ file. If this is the first time you have opened the Symbol Editor or the Footprint Editor you will need to select a working library before being able to import. However, you can save the imported item to any library you choose.

现在你已经完成了这一步,你可以像使用其他任何符号和封装一样使用该符号和封装。

Now you’ve done this, you can use the symbol and footprint just as any others.

获取 USB 元件符号(及其封装)后,从 KiCad 库中添加RP2040元件。接下来,添加电阻和一对标签,将 D+ 和 D- 连接到 RP2040 上的正确引脚。文档指出,需要创建具有精确尺寸和间距的走线来连接这些线路。为此,请为连接分配一个自定义网络类(net class)这样在 PCB 编辑器中绘制这些走线时,它们就能正确创建。

With the USB symbol (and footprint) sourced, add the RP2040 component from the KiCad library. Next, add resistors and a pair of labels to connect the D+ and D- to the correct pins on RP2040. The documentation states that you need to create the traces for these connections with accurate dimensions and clearances. Do this by assigning a custom net class to the connection, or net, so when you draw these traces in the PCB Editor, they’ll be created correctly.

小贴士

创建自定义封装时,务必注意确保元件引脚编号与原理图符号兼容,反之亦然。

Do take care when creating custom footprints to ensure that the component pin number is compatible with your schematic symbol and vice versa.

在原理图编辑器的“原理图设置”对话框中,单击最上方“网络类”窗口中的“+”按钮,添加一个新的网络类并为其命名。请注意,项目中的本地网络类名称应以“/ ”开头——例如,“ /USB_lines” 。选择连接RP2040 D+D-引脚到您添加的USB_D+USB_D-标签的线段,然后右键单击。从下拉菜单中选择“分配网络类” 。在“添加网络类分配”对话框中,您应该会看到已选中的标签USB_D+,在其右侧有一个下拉菜单,用于选择网络类——当前为“默认”,但如果您向下滚动,应该可以看到之前添加的USB_lines网络类。选择该网络类,然后关闭对话框。如图 5-6所示,对USB_D-标签重复此操作。

In the Schematic Setup dialogue in the Schematic Editor, click the + button in the uppermost Net Classes window, add a new net class, and give it a name. Note that local net class names within a project should start with a / — use /USB_lines. Select a wire segment that connects the RP2040 D+ or D- pin out to the USB_D+ or USB_D- label that you added, and then right-click. Select Assign Netclass from the drop-down menu. In the Add Netclass Assignment dialogue box, you should see the selected label USB_D+ and, to the right of it, a drop-down menu to select the net class — this is currently Default, but if you click down, you should be able to see the USB_lines net class that you added earlier. Select this, then close the dialogue box. Repeat this for the USB_D- label as shown in Figure 5-6.

图 5-6:设置和分配网络类

打开PCB编辑器后,使用电路板设置工具(位置与原理图设置工具相同)调整网络类变量。这包括走线宽度、走线间距、过孔尺寸等图5-7)。您需要设置走线宽度和走线间距,以创建USB线路所需的走线——这些关于走线几何形状的信息直接取自RP2040硬件设计 文档(参见2.4.1节, USB)。

After opening the PCB Editor, use the Board Setup tool (in the same positions as the Schematic Setup tool) to adjust the net class variables. This includes the track width, track clearance, via size, and more (Figure 5-7). You’ll need to set the track width and the track clearance to create the track lines that you need for the USB lines — this information on track geometry was taken directly from the Hardware Design with RP2040 documentation (see section 2.4.1, USB).

图 5-7:在 PCB 编辑器的“电路板设置”对话框中设置 USB 线路的网络类变量

我们设计了电源稳压器,并找到了一个与最小设计示例类似的器件;然而,JLC 元件C26537多了一个引脚,并且采用的是SOT-223-3封装。我们有匹配的 KiCad 库封装,但为了确保引脚编号正确且匹配,我们还是快速创建了一个自定义原理图符号(图 5-8)。

We laid out the power regulator and found a similar device to the minimal design example; however, the JLC component C26537 had an extra pin and was in the SOT-223-3 package. We have a matching KiCad library footprint, but it was easier to just make a quick custom schematic symbol to ensure that the pin numbering was correct and matching (Figure 5-8).

图 5-8:一旦确定了目标 JLCPCB 元件,设置电源稳压器就很简单。

轨迹宽度

Trace widths

为了节省空间,并方便布线复杂的芯片,避免电路板尺寸过大,您通常会选择使用更细更小的走线。PCB 制造服务商通常会在其网站上列出他们能够处理的最小走线尺寸。那么,为什么不直接使用电路板制造商提供的最小走线尺寸呢?显然,走线就像导线一样,只能通过一定的电流,超过这个电流值走线就会发热,在极端情况下甚至会熔化或着火。大多数 PCB 设计中,有些区域的电流需求很低,而另一些区域则需要更高的电流。对于 RP2040 电路板来说,一个经验法则是:引出 GPIO 的走线可以非常细,因为 GPIO 的绝对电流限制为 50mA,但通常情况下,您只需要 12mA 的电流即可。相比之下,USB 连接器的电源线可能需要高达 1 安培的电流。为了满足这些不同的应用需求,您需要使用不同宽度的走线。

Often you will want to use thinner and smaller traces simply to save space and allow you to route out complex chips without the board becoming too big. PCB fabrication services will usually have the minimum trace size that they can handle listed on their site somewhere. So why don’t you always just use the smallest trace size your board maker can supply? Well, obviously a trace is like a wire and can only pass a specific amount of current before the trace starts to get hot, and in worse cases, melt or even set on fire. Most PCB designs will have some parts of the board that are very low current with other areas having higher current needs. A rule of thumb for RP2040 boards is that traces breaking out GPIO can be pretty thin as the GPIO have an absolute current limit of 50mA, but more typically you want to only draw up to 12mA. Compare this to the power supply lines coming from the USB connector where these might be drawing up to an amp. To support these different uses, you need different trace widths.

计算走线宽度和电流处理能力可能有点复杂,但网上有很多计算器可以提供帮助。你需要知道(或估算)PCB上走线的高度(一家PCB制造商如果使用更多的铜来制作更高的走线,则可能可以使用更细的走线设计来实现相同的电流处理特性)。

Calculating trace widths and current handling can get a little complex, but there are lots of calculators online that can help. You need to know (or estimate) the height of a trace on a PCB (a PCB house that uses more copper in traces to make a taller trace might be able to use thinner trace designs an achieve the same current handling characteristic).

例如,JLCPCB电路板的标准铜箔重量为1盎司。这对应的走线高度略小于1.4密耳(1密耳等于1/1000英寸)。铜箔重量和走线高度通常以英制单位计算,但如果需要,您可以将其转换为毫米。

For example, the standard copper weight for boards from JLCPCB is 1oz. This results in a trace height of just a shade under 1.4mils (where mils are 1/1000th of an inch). It’s more common for copper weights and traces to be calculated in imperial units, but you can convert it over to mm if needed.

工具孔

从 JLCPCB 订购组装好的 PCB 时,您可能需要考虑定位孔。这些小孔位于您的设计布局中,JLCPCB 的机器会利用它们在组装过程中定位和固定电路板。您可以自行添加这些孔,也可以省略,因为 JLCPCB 会为您放置它们。JLCPCB 的工程师会合理地放置这些孔,不会将它们放置在走线或元件封装的中心;但是,您最好还是手动将它们添加到您的设计中,以便最终确定它们的位置。

When ordering assembled PCBs from JLCPCB, you might need to consider tooling holes. These are small holes placed in your design layout that JLCPCB machines use to locate and hold the boards when they are being assembled. You can add these yourself, or you can omit them, knowing that JLCPCB will place them for you. It’s fair to say that JLCPCB engineers will place the holes sensibly and won’t plonk one through a trace or in the middle of a component footprint; however, you might want to manually add them into your design so that you decide where they are finally placed.

规则是,PCB设计中至少应设置两个孔,最好是三个,并且这些孔应位于对角,彼此之间的距离尽可能远。这些孔应为直径1.152mm的圆形非镀层孔,并带有0.148mm的阻焊层扩展。我们发现,创建这些工装孔最简单的方法是在KiCad库中创建一个自定义元件,然后将其拖放到设计中。

The rules are that a minimum of two, preferably three, holes should be placed in the PCB design, and they should be placed at opposite corners — as far apart as they can practically be. The holes should be 1.152mm diameter circular non-plated holes with a 0.148mm solder mask expansion. we found that the easiest way to create these tooling holes is to create a custom component in the KiCad libraries that you can drag into and place in the design.

要在封装编辑器中创建带工具孔的元件封装,您需要创建一个新的封装,然后添加一个焊盘。选中该焊盘,按E键进入“焊盘属性”对话框。在第一个“常规”选项卡中,将焊盘类型设置为NPTH(非镀通孔),并指定为“机械” 。保持在“常规”选项卡中,确保焊盘形状设置为圆形,直径为 1.152 毫米。最后,单击“焊盘属性”对话框中的第二个选项卡“间隙覆盖和设置”。在此选项卡中,将阻焊层扩展设置为 0.148 毫米。将此封装保存为封装,之后您可以根据需要将其放置在面向 JLCPCB 的设计中。

To make a tooling hole component footprint in the Footprint Editor, you need to create a new footprint and then add a single pad. Selecting the pad, press the E key to enter the Pad Properties dialogue. On the first General tab, set the pad as NPTH, Mechanical in the pad type — NPTH stands for Non-Plated Through-Hole. Staying on the General tab, make sure the pad shape is set to circular and the diameter is 1.152mm. Finally, click onto the second tab in the Pad Properties dialogue called Clearance Overrides and Settings. On this tab, set the solder mask expansion to 0.148mm. Save this as a footprint and you can place them when needed into JLCPCB-oriented designs.

由于本示例并未针对任何特定应用场景,您可以简单地将所有引脚引出到一对排针上,并将它们分别放置在电路板的两侧。原理图基本完成后,即可转到 PCB 编辑器开始布局和布线。

As you’re not aiming for any particular use case with this example, you can simply break out all the pins to a pair of headers that you will place on each side of the board. With the schematic largely complete, you can move over to the PCB Editor to begin the layout and routing.

您可以使用在线计算器来确定所需的走线宽度。您可以在hsmag.cc/tracewidth找到一个非常优秀的计算器。举个简单的例子,将电流设置为 1 安培,铜箔厚度设置为 1盎司/平方英尺。为了方便计算,请忽略可选输入,直接查看内层走线的计算结果。结果显示为 30.8 密耳。将其转换为毫米(乘以 0.0254)后,大约为 0.78 毫米。如果您使用的走线宽度大于此值,例如 1 毫米,则说明走线规格过大。

You can use an online calculator to determine the required trace width. You can find an excellent calculator at hsmag.cc/tracewidth. As a simple example, set the current value to 1 amp and the copper thickness to 1 oz/ft^2. For a simple value, ignore the optional inputs and move straight to reading the results for an internal layer. This says a value of 30.8mils. If you convert this into mm (by multiplying by 0.0254) you get roughly 0.78mm. If you use a trace larger than this, for example 1mm, then you know the trace is overspecified.

最后,关于走线宽度,还有另一个需要考虑的因素:阻抗。对于运行频率较低的PCB(包括本书中的所有项目),这完全不是问题。但是,如果设计频率较高,则可能会出现问题,因为走线周围会产生磁场和电荷,从而干扰电路特性。这是一个冗长而复杂的主题,由于与本书中的设计无关,我们将完全略过。但是,如果您想了解更多信息,或者担心它会给您的设计带来问题,可以在hsmag.cc/impedance上找到很好的介绍。

Finally on trace widths, there is another factor that you may need to consider: Impedance. For PCBs running at lower frequencies including all the projects in this book, it isn’t an issue at all. However, if you move to higher frequency designs, it can cause problems where the trace can begin to create magnetic fields and electric charges around the traces which can interfere with the circuit characteristics. It’s a long and involved subject that we’ll sidestep entirely as it’s not relevant to the designs in this book. However, if you would like to know more, or are concerned about it causing problems in your design, you can find a good introduction at hsmag.cc/impedance.

水晶之谜

Crystal conundrum

在查找最小设计示例项目所使用的元件时,我们遇到的一个难题是晶振;我们在 JLCPCB 元件库中没有找到类似的器件(图 5-9)。我们运用硬件黑客的技巧,研究了其他基于 RP2040 的开源设计所使用的元件,并确保将列表限制在我们已知运行良好的项目中。由于本书前面提到过 Solder Party 的 Stamp,我们查看了它的设计。它看起来简单明了,只用了两个 12pF 的电容,并且在 JLCPCB 上找到了晶振,零件号为C521567。要使用它,需要再次使用 EasyEDA 转换封装。

When looking up the components that the minimal design example project used, one area that challenged us was the crystal; we found no similar device available on the JLCPCB component library (Figure 5-9). Using a consummate hardware hacker’s approach, we looked into what components other open source RP2040-based designs used, making sure to limit the list to projects we knew worked well. Having used Solder Party’s Stamp earlier in this book, we checked out its design. It looked simple and straightforward with just two 12pF capacitors, and on checking JLCPCB, the crystal part was available as part number C521567. To use this, you’d need to again convert the footprint from EasyEDA.

图 5-9:由于 JLCPCB 没有 RP2040 文档推荐的晶振库存,我们需要重新设计电路的这一部分。

在原理图中布置去耦电容非常简单,您应该利用 KiCad 的文本工具添加注释,以便随时提醒自己重要的信息。例如,在RP2040 的硬件设计文档中,它指出 1uF 电容应该放置在 RP2040 的 44 和 45 引脚附近,因此添加原理图注释作为提醒是很有必要的(图 5-10)。

Laying out the decoupling capacitors in the schematic is straightforward, and you should take advantage of the KiCad text tool to add notes, occasionally acting as reminders for important information. In the Hardware design with RP2040 documentation, for example, it shows that the 1uF capacitors should be placed close to pins 44 and 45 on the RP2040, so it makes sense to add a schematic note as a reminder (Figure 5-10).

最小设计示例中使用的闪存芯片可从 JLCPCB 购买,因此您应该采用相同的设计。在 RP2040 硬件设计 文档中,他们添加了一个可选上拉电阻的封装,但发现对于这款芯片来说并不需要,所以您可以省略这部分设计。闪存芯片及其在 PCB 上的相关走线的关键在于它们都位于连续的接地层之上。这意味着您必须仔细考虑走线布局,尤其是在双层板上,因此请以本项目或 Raspberry Pi 项目作为起点。

The flash memory chip used in the minimal design example is available at JLCPCB and, as such, you should go with the same design. In the Hardware design with RP2040 documentation, they have added a footprint for an optional pull-up resistor but found, with this chip, that it wasn’t needed, so you can omit that part of the design. The important thing about the flash chip and the associated traces on the PCB is that it all sits over a continuous ground plane. This means you must think carefully about routing the traces, especially on a two-layer board, so use this project or the Raspberry Pi project as a starting point.

电路板设计中一个我们尚未探讨的有趣之处在于,它具有多种不同的电压,每种电压都有各自的铜箔覆盖区域。这些区域的制作方法与之前的电路板类似,但需要设置优先级,以便不同的覆盖区域能够独立进行覆盖。因此,在电路板的顶层,有一个通用的 3.3V 覆盖区域,一个连接到VBUS 的覆盖区域(VBUS 是 USB 到稳压器的 5V 输入),以及一个位于 RP2040 封装内的小型 1.1V 区域。如图5-11所示,我们将 1.1V 覆盖区域的优先级设置为 2,VBUS区域的优先级设置为 1,而通用的 3.3V 覆盖区域的优先级设置为 0。这表明它们是相互独立的区域。

One interesting aspect of the board design, that we haven’t looked at yet, is that it has numerous different voltages which each have their own copper flood zones. Making these is like how you make any other copper flood, as in previous boards, but you need to set a priority value so that the different floods know how to flood separately. So, on the top layer of the board there is a general 3V3 flood, a flood connected to the VBUS, which is the 5V input from the USB to the voltage regulator, and there is a small 1V1 zone inside the footprint of the RP2040. Notice in Figure 5-11 that we have assigned the 1V1 flooded area priority 2, the VBUS area priority 1, and the general 3V3 priority 0. This essentially shows that they are separate areas.

图 5-10:在原理图编辑器中布局去耦电容的过程相当简单。

我们决定电阻和大部分去耦电容都采用 0402 封装(我们用的是英制尺寸,因为这是业余爱好者中最常用的)。当然,如果我们打算手工组装电路板,就不会选择这种封装,但既然有工程师和机器人来完成这项精细的工作,使用小型封装也无妨。电容值越大,小型封装的电容值精度就越低。因此,虽然 JLCPCB 提供标称 10uF 的 0402 封装元件,但您最好选择更常见、容量更大的 1206 封装。

We decided that for the resistors and most of the decoupling capacitors, we would go for 0402 size packages (we’re using the imperial sizes because these are most common in the hobbyist community). Again, we wouldn’t make this choice if we were planning to assemble this board by hand, but with the assembly engineers and robots doing this fine work, you might as well use the tiny packages. It’s less common for the very tiny packages of capacitor to be of accurate value as they increase in capacitance. So, although JLCPCB does offer components that claim 10uF in 0402 packages, you should go with a more common, larger 1206 variant.

图 5-11:设置不同的优先级以允许不同区域共存
图 5-12: PCB 编辑器中的完整布局

以上涵盖了本项目特有的所有内容。如果您已经完成了前面的章节,可以将之前的经验应用到本项目中。像上一章中的H桥设计这样的小型项目将帮助您熟悉JLCPCB特有的流程。在动手操作RP2040电路板之前,先阅读几遍《RP2040硬件设计》是值得的。最后,请注意,收到组装完成且功能正常的电路板会让人上瘾!

That covers everything unique to this project. If you’ve worked through the previous chapters, you can apply that experience to this project. Smaller projects like the H-Bridge design in the last chapter will help you get used to JLCPCB-specific processes. Reading Hardware design with RP2040 a couple of times before tinkering with an RP2040 board is time well spent. Finally, be warned, having fully assembled and hopefully functional boards delivered to your door is highly addictive!

第六章

Chapter 6

示意图组织

Schematic organisation

在开始大型项目之前,请先整理好你的文件和资料。

Get your sheets in order before starting a larger project

上一章中,你完成了迄今为止最大的项目——一个极简的RP2040开发板。下一章,你将学习如何在此基础上进行扩展。然而,原理图已经相当复杂,如果不加注意,整个设计可能会变得难以管理。本章将向你展示如何保持原理图的简洁、清晰和易于操作。

In the last chapter, you laid out your largest project so far — a minimal RP2040 board and, in the next chapter, you’ll learn how to add to this design. However, the schematic is already quite full and, if you’re not careful, the whole thing could become unmanageable. This chapter will show how you can keep things clean, tidy, and easy to work with.

图 6-1: RP2040 最小示例项目的原理图

如果您查看上一章的项目,并进入原理图编辑器,会发现它看起来非常拥挤(图 6-1)。您可以做的第一件事就是增大原理图的尺寸。依次点击“文件”>“页面设置”,在该对话框中,您可以更改页面尺寸,当前设置为A4。将其更改为A3将为您提供更多空间。

If you view last chapter’s project, and jump into the Schematic Editor, it looks quite cramped (Figure 6-1). One of the first things you can do is to simply increase the schematic size. Navigate to File > Page Settings and, in that dialogue, you can swap the page size, currently at A4. Changing this to A3 will give you plenty more room.

“页面设置”对话框中,请为“标题栏”字段添加一些详细信息。标题栏位于右下角,是一组文本框,用于列出标题修订日期等信息。如果您计划发布项目或将示意图用作文档的一部分,清晰的标题、修订标签和日期将非常有用(图 6-2)。

While you are in this Page Settings dialogue, add some detail to the Title Block fields. This is the lower right-hand corner collection of text boxes that list the title, revision issue date, and more. Clear titles and revision labels and dates are useful if you plan to publish your project or use the schematic as part of documentation (Figure 6-2).

图 6-2:增大示意图页面尺寸并添加清晰的标签是保持条理清晰的良好开端。

原理图尺寸增大并已清晰命名后,让我们使用“添加矩形”工具,在项目电路的不同子部分周围创建图形框,从而进一步整理原理图。首先,使用选择工具选择并移动原理图的各个部分,使其位于可以完整绘制矩形框的位置。

With the schematic size increased and neatly titled, let’s further organise your schematic by creating graphic boxes around different subsections of a project’s circuits with the Add a rectangle tool. First, use the selection tool to select and move parts of the schematic into a position where you can completely draw a rectangle around them.

小贴士

如果无法使用选择框工具完全选择原理图的一部分,请尽可能多地选择,然后按住CTRL键并单击任何遗漏的元件或导线。

If you can’t select a section of schematic completely using the selection box tool, select as much as you can, then press and hold the CTRL key whilst clicking any missed components or wires.

选择“添加矩形”工具(位于右下角)。单击起始位置(矩形的一个角),然后将指针移动到所需的对角位置。绘制矩形后,使用选择工具单击它,您可以拖动锚点来更改其尺寸,或者按键盘上的M键像在原理图编辑器中移动其他对象一样移动矩形。

Select the Add a rectangle tool (in the lower right-hand side). Click the start position (a corner of your rectangle) and then move the pointer to the opposite corner position you desire. Once the rectangle is drawn, click it with the selection tool, and you can either grab the anchor points to change its dimensions, or press M on the keyboard to move the rectangle as you would any other object in the Schematic Editor.

现在,原理图的一部分已被框在一个矩形框内,请使用“添加文本”工具创建标签并将其放置在框内(图 6-3)。您在上一章的 RP2040 最小示例项目中已经这样做过,当时您添加了注释,将电容器放置在靠近特定点的位置。如果您想在原理图中融入一些个人风格,可以使用任何字体作为文本,而不是 KiCad 的默认字体。

With a section of your schematic now encapsulated in a rectangle, use the Add text tool to create and then place labels into the boxes (Figure 6-3). You did this in the previous chapter’s RP2040 minimal example project when you added notes to place capacitors close to certain points. If you want to bring a little of your own house style to schematics, you can use any font for the text, rather than the default KiCad fonts.

图 6-3:添加方框和文本标签有助于组织复杂示意图的各个部分

漫游机器人

Roving Robot

我们将在后续章节的新项目中沿用上一章的RP2040示例。您需要保留原有的RP2040开发板项目,因此需要复制该项目以开发成机器人漫游车平台。

We’re going to use last chapter’s RP2040 example into new projects in future chapters. You’ll want to keep the original RP2040 board project, so you need to make a copy of the project to develop into a robot rover platform.

要复制原始项目,请转到“文件”>“另存为” ,然后选择或创建一个新文件夹来保存项目。在“名称”对话框中输入副本的新名称,然后单击“保存”。虽然并非绝对必要,但最好在文件浏览器中打开新项目文件夹,并删除新项目中不需要的文件。例如,如果您有一个 Gerber 文件文件夹,这些文件可能与新项目无关。任何备份文件也可以删除,因为如果需要,您可能更倾向于返回原始源项目,而不是使用此新分支项目的备份。

To make a copy of the original project, go to File > Save As, then select or create a new folder to save the project to. Type a new name for the copy in the Name dialogue box, then click Save. Although not completely necessary, it’s not a bad idea to then open the new project folder in a file browser and delete any unneeded files for the new project. For example, if you have a Gerber file folder, these probably won’t be relevant to the new project. Any backup files can also be removed as you would probably return to the original source project, if required, rather than use a backup from this new branched project.

第一个新项目是一个轮式机器人。该机器人的基本设计理念是采用四个轮子,全部由N20型电机驱动。这为后续开发提供了多种选择:它既可以使用普通轮子和轮胎,也可以使用麦克纳姆轮——麦克纳姆轮需要单独驱动才能产生其特有的横向和斜向运动。

The first new project is a wheeled robot. The basic premise for the robot is that it is going to have four wheels, all of which are driven by N20-style motors. This gives you options down the line in that it can run with normal style wheels and tyres, but would also work with Mecanum wheels, which need to be driven individually to create the interesting sideways and diagonal motions Mecanum wheels are known for.

设计的一个主要部分是在RP2040板上添加四个电机驱动电路——每个车轮一个。您可以将这四个电机驱动电路添加到A3原理图中,并使用标签或直接接线的方式进行连接。但是,您还可以使用分层图纸来向原理图添加内容。分层图纸是原理图中位于主图纸下方的子图纸,您可以在其中插入可以连接到主顶层原理图的设计。

A primary part of the design is to add four motor driver circuits to the RP2040 board — one for each wheel. You could place the four motor driver circuits into the A3 schematic and wire them using either labels or direct wiring. However, another way you can add content to the schematic is with hierarchical sheets. A hierarchical sheet is a sub-sheet that exists in the schematic below the main page, into which you can insert designs that can be connected to the main top-layer schematic page.

一抹色彩

您可以向原理图添加图像,虽然您可以将图像放置在任何页面上的任何位置,但一个常见的用途是在标题栏区域添加公司徽标。原理图编辑器支持多种图像格式,包括 PNG、JPG、TIFF 和 BMP。您可以在导入图像时调整其大小。这非常实用,因为您可以导入更大、更高 DPI 的图像,然后将其缩小以适应文本框。

You can add images to schematics and, while you can place images anywhere on any page, a common use case for this is to add a company logo to the Title Block area. The Schematic Editor supports a wide range of image formats, including PNG, JPG, TIFF, and BMP. You can rescale the image as you import it. This is useful as you can import a larger, higher DPI image and then scale it down to fit the box.

要将图像添加到原理图中,请单击屏幕右下角的“添加位图”工具图标,然后找到您选择的图像文件。导入对象后,您可以通过拖动图像边界框的角点来移动和缩放图像,同时保持其宽高比。

To add your image to the schematic, click the Add a bitmap tool icon on the lower right-hand side of the screen, and navigate to your chosen image file. Once the object is imported, you can move it and scale it whilst maintaining its aspect ratio by dragging the corners of the image bounding box.

要创建分层图纸,您可以使用原理图编辑器右下角的“添加分层图纸”工具图标,或者按键盘上的S键。接下来,单击并拖动鼠标在原理图中创建一个矩形。单击完成矩形绘制后,将出现“图纸属性”对话框。您可以在此对话框中输入图纸名称,该名称将显示在主原理图页面上的矩形框内。将第一个图纸命名为L9110_Motor_Driver_1。下方有一个用于输入图纸文件名的输入框。目前,该输入框默认显示为untitled.kicad_sch。这是将为该分层图纸创建的单独文件的名称。请将其更改为合适的名称,例如L9110_Motor_Driver_1.kicad_sch

To create a hierarchical sheet, you can use the Add a hierarchical sheet tool icon found in the lower right-hand area of the Schematic Editor, or you can press the S key on your keyboard. Next, click and drag to create a rectangle in the schematic. When you click to finish the rectangle, the Sheet properties dialogue appears. Into this you can put a sheet name, which will be displayed in the rectangle on the main schematic page. Name the first sheet L9110_Motor_Driver_1. Under this is an input box for a sheet file name. It will currently be populated with untitled.kicad_sch. This is the name of a separate file that will be created for this hierarchical sheet. Change this to something appropriate, such as L9110_Motor_Driver_1.kicad_sch.

请注意,图中标有“显示”的复选框默认处于勾选状态(图 6-4)。这意味着在主原理图中,层级视图矩形将显示,并列出这两项信息。建议显示其中一项或两项信息,否则您必须导航到层级视图才能查看其内容,如果您有多个层级视图,这可能会造成混淆。同样,您还可以调整层级视图矩形的外观,例如增加或减少线宽、背景色和边框颜色。这看似无关紧要,但当您处理包含大量层级视图的设计时,能够通过颜色区分它们可以帮助您更快地完成工作。

Notice that there are checkboxes labelled show and, by default, they will be ticked (Figure 6-4). This means that, in the main schematic sheet, the hierarchical sheet rectangle will appear with both pieces of information listed. It is advisable to show one, or both, of these pieces of information or else you must navigate into the hierarchical sheet to see what it contains, which can be confusing if you have multiple hierarchical sheets. Similarly, notice that you can also play with the appearance of the hierarchical sheet rectangle, increasing or decreasing line width, background, and border colours. This might seem frivolous, but when you work in designs with many of hierarchical sheets, being able to differentiate them by colour can help you work quicker.

图 6-4:为新的分层图纸添加名称,并为新的分层图纸原理图文件添加文件名

要从主原理图页面进入新的层级图纸,您可以右键单击矩形框(图 6-5)并选择“进入图纸”,或者双击层级图纸矩形框。此时应该会看到一个全新的空白原理图。

To enter your new hierarchical sheet from the main schematic page, you can either right-click on the rectangle (Figure 6-5) and select Enter sheet, or you can double-click on the hierarchical sheet rectangle. You should be met with a brand-new empty schematic.

图 6-5:放置在原始示意图中的空白层级结构图

现在您可以开始在层级结构图中放置元件并创建电路。首先需要注意的是,任何连接到全局标签或网络的元件都会自动全局连接到这些点。例如,如果您添加一个元件并将其连接到GNDVCC,它们将自动连接到顶层原理图中的相应点,并且在您将这些元件及其连接导入 PCB 编辑器时也会保持连接状态。

You can now begin to place components and create your circuit in the hierarchical sheet. The first thing to note is that anything connected to a global label or net will automatically be connected to those points globally. If, for example, you add a component and connect it to GND and to VCC, they will automatically be connected to those points in the top-layer schematic and will be connected when you import those components and connectivity to the PCB Editor.

如果您将此类组件放置并连接到分层图纸中,返回主图纸时,您将看不到任何从分层图纸矩形区域引出的连接。对于一般的接地和电源连接,这可能没问题,但如果对所有连接都采用这种方法,则可能会造成混淆。在分层图纸中进行连接的常用方法是使用分层标签

If you did place and connect such a component in a hierarchical sheet, when you return to the main sheet you won’t see any connections coming out of the hierarchical sheet rectangle. For general ground and power connections this might be OK, but it may get confusing if you use this approach for all your connectivity. A common way of making connections into and out of hierarchical sheets is to use hierarchical labels.

小贴士

由于分层图纸是一个单独的示意图文件,您可以像以前一样,使用“文件”>“页面设置”来设置标题、页面大小和其他详细信息。

As a hierarchical sheet is a separate schematic file, you can use File>Page Settings to set the title, page size, and other details, as you did earlier.

深入挖掘

Digging deep

要添加层级标签,您可以点击“添加层级标签”工具图标,或者按键盘上的 H 键。此时会弹出“层级标签属性”对话框。在“标签”字段中输入名称。现在,您就可以放置、移动、旋转标签,并将其连接到您的设计中。

To place a hierarchical label, you can either click the Add a hierarchical label tool icon or press H on your keyboard. A Hierarchical Label Properties dialogue will appear. Insert a name into the Label field. You will now have a label you can place, move, and rotate and connect into your design.

图 6-6中,我们创建了层级标签test_hierarchic,并将其连接到 LED 元件符号的阳极端。我们还将全局标签 test 连接到了另一个 LED 元件。退出层级视图非常简单:您可以右键单击并选择“离开视图” ,或者按住ALT键,然后按退格键。

In Figure 6-6, we have made the hierarchical label test_hierarchic and connected it to the anode end of an LED component symbol. We’ve also placed a global label test to another LED component. Moving out of the hierarchical sheet is simple: you can either right-click and select Leave sheet or you can hold ALT and then tap the Backspace key.

图 6-6:

采用层级标签和全局标签设计的层级式表格内部结构

即使在层级图纸中创建了层级标签,您也看不到该连接,直到您右键单击层级图纸矩形,然后从下拉菜单中选择“导入图纸引脚”。现在,您应该可以看到所有层级引脚都与矩形边缘对齐。您可以将这些引脚移动到矩形周围的任意位置,并且可以像连接其他符号一样连接和布线这些标签。

Even after creating a hierarchical label inside a hierarchical sheet, you won’t see that connection until you right-click over the hierarchical sheet rectangle and click Import Sheet Pin from the drop-down menu. You should now see any hierarchical pins appear aligned with the edge of the rectangle. You can move these pins to any position around the rectangle, and you can connect and wire to these labels as you would any other symbol.

图 6-7中,您可以看到图纸矩形内的test_hierarchic标签,它连接到VBUS。请注意,您看不到全局标签test,但该分层图纸内的点将连接到项目原理图中任何带有该全局标签的其他连接。在该分层图纸内,有一个连接到GND符号的连接,因此该点连接到项目的全局GND标签。

In Figure 6-7 you can see the test_hierarchic label in the sheet rectangle, and it is wired to VBUS. Note that you can’t see the global label test, but that point inside the hierarchical sheet will be connected to any other connections with that global label anywhere in the project schematic. Inside this hierarchical sheet, there is a connection to a GND symbol and, as such, that point is connected to the project’s global GND label.

图 6-7:从主原理图看到的测试分层结构对象。分层引脚已连接到 VBUS。

对于机器人漫游车的设计,我们力求简单经济,因此选择了L9110电机驱动IC,因为它适用于N20电机,价格实惠,而且JLCPCB库存充足。L9110周围的电路非常简单(图6-8),电机输出端并联了几个上拉电阻和一个去耦电容。在为电机驱动电路创建层级图时,我们使用层级标签来表示两个信号输入。虽然我们也可以选择将电机输出作为层级标签,但将电机输出连接器符号添加到层级图内部会更简洁,避免主原理图过于杂乱。

For the robot rover design, let’s keep it simple and affordable and use the L9110 motor driver IC as it’s adequate for the N20 motors, affordable, and there is a large amount of stock available on JLCPCB. The circuit around the L9110 is straightforward (Figure 6-8), with a couple of pull-up resistors and a decoupling capacitor across the motor outputs. When we created a hierarchical sheet for the motor driver circuit, we used hierarchical labels to create the two signal inputs. We could have opted to have the motor outputs as hierarchical labels, but it was cleaner to add the motor output connector symbols inside the hierarchical sheet, avoiding more clutter on the main schematic.

图 6-8:各电机对应的 L9110 电路。请注意 IB 和 IA 引脚上使用的层级标签。

使用层级式工作表的一大好处是,您可以快速复制它们(或其内容),从而在同一项目或其他项目中创建多个类似的模块。在机器人漫游车项目中,我们只需添加三个层级式工作表,并按顺序命名为Motor_Channel_1Motor_Channel_2Motor_Channel_3Motor_Channel_4

One of the great benefits of using hierarchical sheets is that you can quickly copy them (or their contents) to create multiples of similar modules, either within the same project or into other projects. In the robot rover project, we have simply added three more hierarchical sheets and named them sequentially as Motor_Channel_1, Motor_Channel_2, Motor_Channel_3, and Motor_Channel_4.

然后,我们将Motor_Channel_1的内容复制粘贴到各个不同的层级图中。每次复制 L9110 电路时,我们都会重新标记层级引脚,以确保每个电机通道的引脚唯一(图 6-9)。之后,您可以使用之前在每个电机通道层级图中导入引脚的功能,即可将引脚连接到 RP2040 上您选择的 GPIO 引脚——可以直接连接,也可以使用标签连接,以保持主原理图的整洁。

We then copied and pasted the contents of Motor_Channel_1 into each different hierarchical sheet. Each time we copied the L9110 circuit, we relabelled the hierarchical pins so that each motor channel was unique (Figure 6-9). You can then use the Import Sheet Pin function used earlier on each of the motor channel hierarchical sheets, and you are ready to wire the pins to your chosen GPIO pins on the RP2040 — either directly or using labels to again keep the main schematic clean and tidy.

图 6-9:每个 L9110 驱动电路都位于其自身的层级结构中,各个电机驱动引脚均已引出,准备连接到 RP2040。

为了帮助你理解层级式图纸,你应该浏览一些使用 KiCad 的开源硬件项目。你肯定会发现许多不同的组织和项目管理方法。

To help you understand hierarchical sheets, you should look through some open-source hardware projects that have used KiCad. You’ll certainly find lots of different approaches to organisation and project management.

大型项目

KiCad 的一个优点是,您可以根据自身需求或思维方式采用多种不同的方法。其中一种方法是使用扁平化的层级结构来布局原理图。这种方法实际上是将第一张原理图页变成一个“容器页”,所有子页都位于其中。这样,您就可以在每张子页中使用通用标签和全局标签,而无需在最顶层的主原理图页上绘制任何连接线。

One thing about KiCad is that you can use many different approaches, depending on your needs or your way of thinking. One such approach is to use a flat hierarchy for your schematic layout. This essentially turns the first schematic sheet into a kind of holding sheet where all the hierarchical sheets are held. You can then, in each sheet, use general and global labels so you don’t need to draw any connectivity on the main topmost schematic.

虽然这可能会让其他打开你项目的人暂时感到困惑,但这是一种将大型项目组织成特定部分的绝妙方法。由于每个层级图纸都是一个独立的原理图文件,因此你可以在开发过程中根据需要单独处理每个文件。

Although this might momentarily confuse anyone else opening your project, it’s a brilliant way to organise a particularly large project into specific sections. As each hierarchical sheet is an individual schematic file, you can simply work on each file individually as needed in development.

如果在主原理图中复制并粘贴一个层级式图纸矩形,图纸名称会自动添加并递增一个数字。例如, 图纸名称会变成sheet1,然后变成sheet2。如果您创建了一个名为Something_1 的图纸,然后复制并粘贴,则复制的图纸名称会递增为Something_2

If you copy and paste a hierarchical sheet rectangle in the main schematic, it will automatically add and increment a number to the name of the sheet. So, sheet would become sheet1, then sheet2. If you created a first sheet called Something_1 and copied and pasted it, the clone would increment to Something_2.

第七章

Chapter 7

找到合适的形状

Get the right shape

当您的PCB是结构的一部分时,它们必须精确无误。

When your PCBs are part of the structure, they need to be accurate

将印刷电路板 (PCB) 作为物体的机械部件集成到项目中已变得越来越普遍。在上一章中,您学习了层级式电路板,并设计了一个电机驱动电路,您可以复制粘贴该电路图,将其添加到项目中。在本部分中,您将创建一个简单的机器人漫游车,我们称之为“stoRPer”。“stoRPer”这个名字是对上世纪 80 年代一款深受喜爱的儿童玩具“Stomper”的戏仿。

It’s increasingly common for projects to incorporate PCBs as a mechanical part of an object. In the last chapter, you looked at hierarchical sheets and laid out a motor driving circuit that you could copy and paste to add motor drivers to a project. In this part, you are going to create a simple robot rover that we call ‘stoRPer’. StoRPer is a tongue-in-cheek reference to a favourite childhood toy from the 1980s: the ‘Stomper’.

图 7-1:以 PCB 作为其主要底盘组件的 stoRPer 机器人原型

Stomper是玩具公司Schaper推出的首款四轮驱动电动玩具车。尽管没有遥控功能,但人们仍然乐此不疲地搭建障碍赛道,或在陡坡上进行测试。

The Stomper, by toy company Schaper, was the first ever four-wheel drive electric toy car. Despite no form of remote control, they were great fun to try and build obstacle courses for, or to test on steep gradients.

我们想要Stomper的合理扭矩和四轮驱动特性,但又想加入Raspberry Pi Pico,使其成为一个更有趣、更易于控制的平台——于是,就有了“stoRPer”。它采用全轮驱动(AWD)设计,以便我们可以使用麦卡努姆轮。您可以在https://hsmag.cc/stoRPerGit找到该项目的文件。

We wanted the reasonable torque and the four-wheel drive aspects of the Stomper but with the addition of a Raspberry Pi Pico to make it a more interesting and controllable platform — so, ‘stoRPer’ it is. It’s designed with all-wheel drive (AWD) so that we can work with Meccanum wheels. You can find the files for this project at https://hsmag.cc/stoRPerGit.

在这个项目中,您将使用 Pico 作为模块,并重点关注如何将主 PCB 板用作机械部件和电路。设计思路是,PCB 板将构成 stoRPer 的底盘,电机则通过一些 3D 打印部件固定在 PCB 底盘上。因此,您需要能够精确地放置元件并创建 PCB 几何形状,以确保所有部件能够完美契合。本章还将介绍如何在打印或将 PCB 板送去加工之前,检查 PCB 板和 3D 打印模型是否能够完美契合。

You will use a Pico as a module on this build and focus on using the main PCB as a mechanical part as well as a circuit. The idea is that the PCB will form the chassis of the stoRPer, with the motors clamped to the PCB chassis using some 3D-printed parts. Therefore, you need to be capable of placing components and creating PCB geometry accurately in order for everything to fit together. This chapter also looks at how you can check whether PCB and 3D-printed models will fit together before printing or sending out the PCB for fabrication.

首要任务之一是在符号编辑器中创建 Pico 符号元件。我们在第 3 章“库、符号和封装”中介绍了如何创建符号,虽然这里不会赘述所有步骤,但您可以运用在该章节中学到的技能来创建 Pico 元件。我们决定不在原理图符号或 PCB 封装中包含 Pico 的三个调试引脚。部分原因是,不同型号的 Pico 的调试引脚在电路板上的位置不同,而且由于我们计划将 Pico 安装到此项目中,因此如果需要,我们仍然可以与调试引脚进行交互/连接。因此,我们在符号编辑器中布局了一个简单的 40 引脚元件,并将其导入到原理图编辑器中,如图 7-2所示。

One of the first jobs is to create a Pico symbol component in the Symbol Editor. We covered creating symbols in Chapter 3, Libraries, symbols and footprints, and while we won’t go over all the steps here, you can apply the skills you learned in that chapter to create your Pico component. We decided not to include the Pico’s three debug pins on either the schematic symbol or the PCB footprint. This was partly because, across the different Pico models, they are physically in different positions on the board and, as we intend to have a Pico mounted onto this project, we can still interact/wire to the debug pins if needed. As such, we laid out a simple 40-pin component in the Symbol Editor and brought it into the Schematic Editor, as shown in Figure 7-2.

图 7-2:一个自定义的 Pico 符号,其中大部分引脚已引出

快速连接所有接地端后,我们开始连接四个分层图纸,每个图纸内都包含一个基于 L9110S 电机驱动 IC 的电路。第 6 章“原理图组织”介绍了分层图纸的使用方法,但您可以在图 7-3中看到电路布局。四个电机驱动器各自占据一个图纸,并引出两个引脚。我们使用标签 A1、B1、A2、B2 等将这些引脚组连接到 Pico 符号。Pico 符号的其余引脚已引出并连接到一些多针连接器,准备在 PCB 上进行连接。

After quickly connecting all the ground points, we set about connecting four hierarchical sheets, each with an L9110S motor driver IC-based circuit inside. Chapter 6, Schematic organisation covered working with hierarchical sheets, but you can see the circuit layout in Figure 7-3. Each of the four motor drivers has its own sheet and has two pins broken out. We’ve connected these sets of pins to the Pico symbol using labels A1, B1, A2, B2, etc. The rest of the Pico’s pins are broken out and connected to some multi-pin connectors, ready to be broken out on the PCB.

图 7-3: L9110S 电机驱动电路的布局,克隆为四个分层图纸。

对于 stoRPer 项目,我们决定使用 Pico 芯片上的通孔排针焊盘而非半孔连接器来安装 Pico。这意味着 Pico 芯片无法与电路板齐平安装,但同时也意味着 Pico 芯片的尺寸更小。您也可以选择使用排针插座,以便将 Pico 芯片临时安装到 PCB 上。

For the stoRPer project, we’ve decided to mount the Pico using the through-hole header pads on the Pico rather than the castellated edge connectors. This means that you won’t be mounting the Pico flush to the project, but it does mean that the Pico footprint is thinner. You could also choose to use header sockets to allow the Pico to be temporarily mounted to the PCB.

Pico 上的排针焊盘采用 2.54mm 间距的网格布局,两侧各 20 个引脚,间距为 7*2.54mm。这使得布局非常简便——只需在封装编辑器中按 2.54mm 网格添加焊盘即可(图 7-4)。此外,您还需要在丝印层上放置一个矩形框,以精确指示电路板的位置。

The header pin pads on the Pico lie in a 2.54mm pitch grid, with the 20 pins on either side being separated by 7*2.54mm. This makes them easy to lay out — simply add pads on a 2.54mm grid in the Footprint Editor (Figure 7-4). You’ll also want to be able to place a rectangle on the silkscreen layer that accurately shows the position of the board.

有很多孔

在创建包含大量通孔焊盘的封装时,KiCad 让操作变得简单:只需单击添加焊盘,工具就会自动跳转到下一个数字焊盘供您放置。但是,如果您已经放置并定位了大量焊盘,却发现需要更改所有焊盘的属性,这可能会很麻烦。不过,KiCad 也考虑到了这一点。例如,当我们为 Raspberry Pi Pico 创建封装时,在布局了 40 个标准通孔焊盘后,我们决定增加内孔直径和整体外径。封装编辑器能够识别出这种情况,因此,您只需将一个焊盘的属性更改为所需的属性,然后在选中已调整的单个焊盘的情况下,右键单击并选择“将焊盘属性推送到其他焊盘…”,即可使所有兼容的焊盘应用新的属性。

When creating footprints with lots of through-hole pads, KiCad makes it simple: you click to add a pad and then the tool indexes to the next numerical pad for you to place. If you’ve placed and positioned a lot of pads though, it can be annoying to realise that you need to change an aspect of the pad’s properties for all of them. KiCad has you covered, though. As an example, when we made the footprint for a Raspberry Pi Pico, after laying out 40 standard through-hole pads, we decided to increase the internal hole diameter and the overall outer diameter. The Footprint Editor conveniently recognises that this is a common situation and, as such, you can simply change one pad to your desired pad properties and then, with your adjusted single pad highlighted, you can right-click and select Push Pad Properties to Other Pads… to make all compatible pads take on the new characteristics.

图 7-4:创建简单而精确的 Pico 封装

查阅 Pico 的文档,您可以找到一张技术图纸,图纸显示 Pico 的外边缘尺寸为 51mm × 21mm。您还需要考虑这个矩形相对于您刚刚创建的焊盘的位置。例如,您可以在技术图纸中看到,相对于左上引脚(引脚 1)的中心,Pico 的左上角在 Y 轴方向上高出 1.37mm,在 X 轴方向上向左偏移 1.61mm。要使用此信息,请返回封装编辑器,并将指针放在您为引脚 1 放置的焊盘中心的网格点上。

Consulting the Pico documentation, you can find a technical drawing and see that the outer edge of the Pico is 51mm × 21mm. You also need to consider the position of this rectangle relative to the pads that you just created. You can see in the technical drawing, for example, that relative to the centre of the upper left-hand pin (pin 1), the upper-left corner of the Pico is 1.37mm higher in the Y axis and 1.61mm over to the left in the X axis. To use this information, go back into the Footprint Editor and place your pointer on the grid point in the centre of the pad you placed for pin 1.

此时,您可以按空格键将页面的局部原点设置为 (0,0)。您可以通过移动指针并观察屏幕底部来检查这一点,指针移动的距离应该相对于该点增加。然后,您可以将用户网格设置为 1 毫米间距,并使用该网格绘制一个 51 毫米 × 21 毫米的矩形。选中该矩形后,您可以右键单击并在下拉菜单中滚动到“定位工具”>“相对于…”。选择此选项后,您将看到一个对话框。在对话框中,单击以选择“使用局部原点”,然后根据您从技术图纸中得出的数值调整“X 偏移”“Y 偏移” (图 7-5)。请注意,默认情况下,矩形的原点位于左上角。使用此方法,您可以非常精确地放置元素。

You can press the space bar to set the local origin of the page to be 0,0 at this point. You can check this by looking at the bottom of the screen as you move the pointer, the distance should increase relative to this point. You can then set a user grid to 1mm spacing and use this grid to draw a 51mm × 21mm rectangle. If you then select the rectangle, you can right-click and scroll in the drop-down menu to Positioning Tools > Position Relative To…. Selecting this, you will see a dialogue box. In the dialogue box, click to select Use Local Origin and then adjust the Offset X and Offset Y by the amounts you derived from the technical drawing (Figure 7-5). Note that, by default, the origin corner of the rectangle is the top left-hand corner. Using this method, you can place items with incredible accuracy.

图 7-5:使用“相对于…的位置”定位工具在封装编辑器中精确放置对象

值得注意的是,尽管 stoRPer 机器人的机械设计相对简单(一块矩形 PCB),但您仍然需要能够将封装精确地放置在边缘切割区域内。在设计此封装以及其他封装时,值得考虑封装编辑器中的原点位置,并将器件放置在相对于该原点的已知位置。我们选择将 Pico 封装放置在丝印框左上角(代表 Pico 边缘)处,该位置是 1mm 网格间距的原点。这意味着,之后当我们在 PCB 编辑器中放置代表 PCB 边缘的矩形时,我们可以将其放置在 Pico 位于正中心的位置,并且较大的矩形也位于 1mm 网格坐标上。

One thing of note is that despite the stoRPer robot design being relatively simple mechanically — a rectangular PCB — you need to be able to place footprints accurately within the edge cut area. When designing this and other footprints, it’s worth considering where your origin point is in the Footprint Editor and placing the device in a known position relative to it. We opted to place the Pico footprint so that the upper left-hand corner of the silkscreen box depicting the edge of the Pico was the origin point on a 1mm grid spacing. This meant that later, when we placed a rectangle in the PCB Editor that represented the edge of the PCB, we could place it in a position such that Pico is dead centre, with the larger box also placed on a 1mm grid coordinate.

在 KiCad 中测试了几个测试盒后,我们最终确定矩形机箱的尺寸为 64mm × 86mm。建议使用 Inkscape 绘制矩形,因为这样可以轻松地为矩形的每个角添加 2mm 的半径。有关导入图形的详细信息,请参阅“雕刻路径”部分。您可以使用“文件”>“导入”>“图形”功能,轻松地将 Inkscape 中绘制的 SVG 格式矩形导入到边缘切割图层中。

After playing with a few test boxes in KiCad, we decided the rectangular chassis dimensions would be 64mm × 86mm. You should use Inkscape to draw a rectangle as you can easily add a 2mm radius to each corner of the rectangle. See “Carving a path” for details on importing graphics. You can easily import a rectangle you draw as an SVG in Inkscape into the edge cuts layer using the File > Import > Graphics function.

Pico 放置好并确定好 PCB 边缘后,您需要考虑电机的物理安装位置。我们建议使用性能优异的 N20 型减速电机,每个电机驱动电路安装一个。您需要 3D 打印一些支架来固定电机,因此需要在电机周围预留一些空间,并在设计电机安装座的占位图时考虑这一点。

With the Pico placed and the PCB edge defined, you need to consider the physical mounts for the motors. We suggest using the excellent N20-style geared motors, mounting one for each of the four motor driver circuits. You’ll want to 3D-print some brackets to clamp the motors into position, so you need to leave some space for the 3D print material around the motor, and need to take this into account when creating a footprint for the motor mount.

免费书籍

树莓派出版社出版的免费下载书籍《面向创客的 FreeCAD》探讨了 KiCad StepUp 工作台的使用。它能够简化将 KiCad 项目作为 3D 对象导入 FreeCAD 的过程,并支持创建 3D 组件以将其添加到 KiCad 的 3D PCB 查看器中(图 7-6)。

The free-to-download book FreeCAD for Makers from Raspberry Pi Press looks at the use of the KiCad StepUp workbench. This enables and simplifies importing KiCad projects as 3D objects into FreeCAD, as well as the creation of 3D components for inclusion into KiCad’s 3D PCB viewer (Figure 7-6).

这套工具功能极其强大,值得深入探索。不过,在这个项目中,我们只是想确认一下在 FreeCAD 中创建的电机夹具是否适用于 PCB 底盘。您可以使用“文件”>“导出”,然后选择STEP…选项导出 STEP 文件,该文件可以导入到 FreeCAD 中;但是,这样会缺少铜层和丝印层的细节信息,而这些信息对于检查机械组件是否覆盖 PCB 设计的某些部分可能至关重要。一个简单的解决方法是导出 WRL 文件。WRL 文件通常用于虚拟现实资源,但在 KiCad 中,WRL 文件的优势在于它包含了 PCB 的所有视觉细节。

It’s an incredibly powerful suite of tools and is worth exploring. For this project, however, we just wanted to check if the motor clamp we had created in FreeCAD would fit the PCB chassis. You can use File > Export and select the STEP… option to export a STEP file which can be imported into FreeCAD; however, this will lack the details of the copper layers and silkscreen which you might need to see to check if mechanical components cover aspects of your PCB design. One simple approach that solves this is to export a WRL file. WRL files are file types often used by assets destined for use in virtual reality, but they have the advantage in KiCad that a WRL export contains all the visual details of your PCB.

我们使用“文件”>“导出”>“VRML…”导出WRL文件,然后在FreeCAD的新文档中使用“文件”>“导入”导入该文件。我们制作了一个简单的N20夹具组件,其两个角的圆角半径为2mm,与PCB和N20电机夹具的封装尺寸相匹配。虽然我们可以使用装配工作台(例如FreeCAD中的A2plus)来约束夹具的位置,但为了进行简单的检查,我们可以移动零件进行对齐,以便直观地检查其外观。

We used File > Export > ‘VRML…’ to export a WRL file, and then we used File > Import in a new document in FreeCAD to import the file. We’d made a simple N20 clamp component which had 2mm radius corners on two corners matching the PCB and N20 motor clamp footprint. While we could have used an Assembly workbench, such as A2plus in FreeCAD, to constrain the clamp in position, for a simple check, we can move the part into alignment to visually check how it looks.

图 7-6: KiCAD 和 FreeCAD 的组合构成了一个优秀的开源工具链

经过一番考虑,我们设计了一个自定义封装,它由两个并排排列的非镀通孔 (NPTH) 机械焊盘组成。这两个焊盘中心距为 26 毫米,间距为 1 毫米。要放置 NPTH 机械孔,请先放置一个普通焊盘,然后按E键在“焊盘属性”对话框中更改焊盘类型。将每个 NPTH 孔的内径设置为 2.1 毫米,以便为小型 M2 螺栓留出空间。

After some consideration, we created a custom footprint which consisted of two non-plated through-hole (NPTH) mechanical pads placed in-line. These were placed at a distance between centres of 26mm, placed on a 1mm grid spacing. To place an NPTH mechanical hole, you place a regular pad and then press E to change the pad type in the Pad Properties dialogue. Set each NPTH hole to 2.1mm internal diameter to create clearance for a small M2 bolt.

为了完成 N20 电机安装夹的封装,请添加一个丝印矩形,其尺寸设置为 3D 打印安装座底座的尺寸图 7-7)。要添加这些安装座(它们没有与任何电子元件连接),请单击“添加封装”工具图标,然后以类似于在原理图中放置符号的方式选择封装。

To finish the footprint for the N20 motor mount clamps, add a silkscreen rectangle set to the dimensions of the base of the 3D-printable mount design (Figure 7-7). To add these mounts (which aren’t connected to anything electronically) click the Add a footprint tool icon and select a footprint in a similar manner to how you would place a symbol in a schematic.

图 7-7:用于安装 N20 电机和夹具的机械结构示意图
小贴士

随着 stoRPer 设计的演变,我们使用 KiCad 中在F.SilkscreenUser.Comments图层上绘制的简单矩形框作为指导和视觉辅助。

As the stoRPer design evolved, we used simple rectangular boxes drawn in KiCad on either the F.Silkscreen or the User.Comments layer as guides and visual aids.

在 KiCad 中,向丝印层添加和移除文本元素相当简单。对于技术性较强的 PCB(而非艺术性 PCB),我们通常在布局 PCB 设计时不太关注丝印层,然后在开发后期再处理丝印层。通常,首要任务之一就是移除使用默认库封装自动放置在丝印层上的不需要的元素。

Adding and removing text-based elements to a silkscreen layer is reasonably straightforward in KiCad. On more technical PCBs (as opposed to artistic PCBs) we often lay out PCB designs with little regard for the silkscreen and then sort the silkscreen layer out later in the development. Often, one of the first tasks is to remove unwanted elements on the silkscreen that have been automatically placed by using default library footprints.

您可以选择正确的丝印层(通常是正面丝印层F.Silkscreen),对于诸如封装参考注释之类的项目,单击选中,然后移动或按Delete键删除。此参考注释通常位置不佳,可能位于其他零件或组件下方或上方。

You can select the correct silkscreen layer (often the front silkscreen F.Silkscreen), and for items such as footprint reference annotation, click to select them, then move them or press the Delete key to remove the item. It’s common for this reference to not be placed optimally and may sit under or across other parts and components.

带注释的参考编号由封装关联过程中原理图的自动注释以及元件类型构成,例如R代表电阻器,C代表电容器,J代表连接器,U代表集成电路等。由于它们取代了占位符Ref*标识符,因此它们独立于主要封装设计,因此可以轻松删除。

The annotated reference is formed from both the automatic annotation of the schematic during the footprint association process and the type of component it is, so R for resistor, C for capacitor, J for connector, U for IC, etc. As they replace the placeholder Ref* designator, they are independent of the main footprint design and, as such, can be removed with ease.

如果在整理 PCB 设计时,您想要移动某个封装的丝印图案,则需要在封装编辑器中进行编辑。KiCad 可以轻松编辑封装,并将更改仅应用于当前项目中的单个封装,而不是将更改推送到全局封装库。在 PCB 中选择目标封装后,按Control + E键 即可在封装编辑器中打开该封装。您应该会在编辑器中看到该封装,窗口左上角会显示“ 正在编辑电路板上的 J4”的消息。保存操作只会更新电路板,其中J4是您打开的任何封装的参考引脚(图 7-8)。现在,您可以对封装进行所需的任何更改,包括删除或更改图形丝印元素。

If, when tidying the PCB design, you want to move a part of the silkscreen design of a footprint, you will need to edit that in the Footprint Editor. KiCad makes it easy to edit the footprint and apply the changes just to the individual footprint within this project rather than pushing the changes to the global footprint library. With a target footprint selected in your PCB, press Control and E to open the footprint in the Footprint Editor. You should see the footprint in the editor with a message in the upper left-hand corner of the window that reads Editing J4 from board. Saving will update the board only, where J4 will be the reference of whatever footprint you have opened (Figure 7-8). You can now make any changes to the footprint that you require, including deletions or changes to the graphical silkscreen elements.

图 7-8:在 PCB 编辑器中,选中元件并在封装编辑器中打开该元件后,可以选择仅编辑该封装的特定实例。

您经常需要在电路板设计中添加文本元件,KiCad 让这一操作变得非常简单。单击 “添加文本项”工具图标,然后在 PCB 设计中单击。“文本属性”对话框允许您插入文本、更改字体和大小,以及更改文本方向。KiCad 最近新增了“镂空”选项(图 7-9 )。如果您在“文本属性”对话框中输入一些文本,然后选中“镂空” 复选框,则文本将以实心丝印块的形式呈现,并移除文本内容。这种效果非常出色,外观简洁美观,而且清晰易读——这是一个非常实用的新功能(图 7-10)。

You will often want to add text-based components to board designs, and KiCad makes this straightforward. Click the Add a text item tool icon and then click in the PCB design. The Text Properties dialogue lets you insert text, make changes to the font and size, as well as change the orientation of text. One recent addition to KiCad is the Knockout option (Figure 7-9). If you input some text into the Text Properties dialogue and click the Knockout checkbox, then the text will be created as a solid silkscreen block with the text removed. It’s a great effect, looks smart, and is very readable — a welcome new feature (Figure 7-10).

图 7-9:文本属性对话框,您可以在其中设置文本功能,包括新增的“镂空”功能。
图 7-10: KiCad 7 的一个新功能是能够添加镂空文字项,其中文字是从丝印层上的一个小方块中减去的。

最后,在添加文本时,有时您可能希望将文本作为图形而不是直接作为文本添加到丝印层。您之前学习过如何导入图形来创建边缘切割几何图形以及如何从 Inkscape 导入徽标图形。如果您使用 Inkscape 中的文本创建工具,然后直接尝试将其作为图形元素加载,则会失败,因为 KiCad 的 SVG 导入功能无法识别文本元素。这很容易解决。例如,您可以在 Inkscape 中创建文本,然后选中该文本对象,单击“路径”>“对象到路径”图 7-11)。接下来,在 Inkscape 中编辑文档属性,使文档大小与文本对象的大小相同,然后将文件另存为标准 SVG 文件。在 PCB 编辑器中,选择“文件”>“导入”>“图形”导入该文件,并确保选择正确的F.Silkscreen作为图形层。这样,文本图形即可正确导入,并可放置在设计中的所需位置。

Finally on adding text, sometimes you might like to add text to the silkscreen layer as a graphic rather than directly as text. You previously learned about importing graphics for creating edge cuts geometry and for importing logo graphics from Inkscape. If you use the text creation tools in Inkscape and then directly try to load them as a graphic element, this will fail, as KiCad SVG import doesn’t recognise the text elements. This is easy to rectify. For example, you can create your stoRPer text in Inkscape, then, with the text object selected, click Path > Object to Path (Figure 7-11). Next, edit the document properties in Inkscape so that the document is the size of the text object — then save the file as a standard SVG. In the PCB Editor, select File > Import > Graphics to import the file, ensuring to select the correct F.Silkscreen as the graphic layer. The text graphic then imports correctly and can be placed in the design where required.

图 7-11:在 Inkscape 中将文本对象转换为路径,以便导入 KiCad

现在一切都准备就绪,您可以放心地将文件发送出去进行生产——相信您的机器人能够完美组装。

You’ve now got everything in the right place, so you can send the file off to be manufactured — confident that your robot will fit together.

第八章

Chapter 8

不同的基质

Different substrates

印刷电路板(PCB)就像一个铜夹层——选择合适的填充物至关重要。

A PCB is a copper sandwich — pick the right filling

到目前为止,本书中您已经设计好了PCB,并使用最常见的PCB材料——FR4——进行了制造。在FR4上,铜线位于玻璃纤维上,这也是大多数人听到“PCB”一词时首先想到的。然而,这并非唯一选择,大多数PCB制造商都提供各种不同的PCB材料。电路本身通常仍然是铜,但这些铜线位于其他材料之上。让我们来看看一些其他选择。

So far in this book, you have designed your PCBs and had them manufactured using the most common PCB material — FR4. On FR4, copper traces sit on top of fibreglass, and this is what most people think of when they hear the term ‘PCB’. However, it’s not the only option, and most of the PCB fabrication houses offer a variety of different materials that they can make a PCB from. The circuit is typically still copper, but these traces sit on top of other materials. Let’s look at some options.

图 8-1: OSH Park 公司制造的一些小型聚酰胺柔性 PCB 天线

FR4是PCB(印刷电路板)介电层(即非导电部分)的标准材料。FR4是一种复合玻璃纤维材料,由细玻璃纤维增​​强材料和环氧树脂组成,具有极低的导电性。“FR”是“阻燃”(fire-retardant)的缩写,这也是该材料众多优点和安全特性之一。虽然玻璃纤维复合材料本身就具有一定的阻燃性能,但FR4中添加了溴,可以有效减缓火势蔓延。

FR4 is a standard of material for the dielectric, the non-conducting part of a PCB. FR4 is a type of composite fibreglass material, made up from fine glass reinforcing fibres and epoxy resin, and is very non-conductive. ‘FR’ is an abbreviation for ‘fire-retardant’, which is one of the many benefits and safety features of the material. Whilst fibreglass composite materials have inherent fire-resistant qualities, FR4 has bromine added which will reduce the spread of fire.

黄金或白银

在PCB制造过程中,您还可以做出许多其他选择。其中一项选择是裸露铜焊盘的表面处理方式。这些处理方式包括不同类型的覆盖层或电镀层,其作用既能方便元件、焊料或焊膏的安装,又能防止裸露的铜焊盘氧化。

There are lots of other choices you can make when getting a PCB fabricated. One choice is the type of surface finish applied to any exposed copper pads. These take the form of differing types of covering or plating, which act to both allow the easy fitting of components, solder, or solder paste, whilst stopping bare copper pads from oxidising if left uncovered.

热风整平 (HASL) 是一种常见的工艺,即将电路板完全浸入熔融焊料中,取出后用热风吹走多余的焊料。这样就能使所有铜箔区域都被一层平整的薄焊料覆盖。这项技术历史悠久,已在 PCB 制造领域应用数十年,因此通常价格实惠。它易于焊接,并能有效防止氧化。此外,它的保质期长,即使长时间不进行 PCB 焊接,也能保持良好的状态。最后,HASL 通常提供含铅和无铅两种选择。

Hot Air Solder Levelling (HASL) is a common option where the board is dipped fully into molten solder, removed, and excess solder driven off with — you guessed it — hot air. This results in all copper areas being covered in a flat, thin layer of solder. It’s an older technology and has been used in PCB fabrication for multiple decades and, as such, it’s usually an affordable option. It is easy to solder onto and offers good protection against oxidisation. It has a long shelf life, so if you don’t get around to populating your PCBs for a long time, they will still be in good condition. Finally, HASL is often offered in lead or lead-free options.

化学镀镍浸金 (ENIG) 是一种新型技术,它在 PCB 的裸露铜层上镀上两层涂层。铜层上方是一层薄薄的硬镍层,形成一道屏障,防止铜氧化。为了防止镍层氧化,在其上方再浸镀一层薄薄的金。当元件焊接在 ENIG 表面上时,它们会与镍层形成牢固的焊接,进而与下方的铜层牢固连接。ENIG 也适用于覆盖 PCB 上的大面积区域,因此已成为一种流行的选择。

Electroless Nickel Immersion Gold (ENIG) is a newer technology that applies a two-layer coating to the exposed copper parts of a PCB. The layer directly on top of the copper is a thin layer of hard nickel which creates a barrier stopping the copper from oxidising. To stop the nickel plating from oxidising, a fine layer of gold is immersion-plated over the top. When components are soldered onto ENIG surfaces, they create a strong bond with the nickel layer, and therefore the copper underneath. ENIG is also suitable for covering larger planes on the PCB, so has become a popular choice.

还有其他表面处理方法,如浸锡有机涂层(OSP) 和浸银,但 HASL 和 ENIG 最为常见。

There are other surface finishes, such as Immersion Tin, Organic Coating (OSP), and Immersion Silver, but HASL and ENIG are most common.

例如,JLCPCB默认选择含铅HASL涂层,但您可以切换到无铅HASL或ENIG涂层。OSH Park的PCB均采用ENIG表面处理。PCBWay则提供更广泛的涂层选择,包括HASL、ENIG、OSP等——您甚至可以指定完全不涂层。

For example, JLCPCB has leaded HASL selected as default, but you can switch to lead-free HASL or ENIG. OSH Park PCBs are all created with an ENIG surface finish. Over on PCBWay, you can select from a larger range that includes HASL, ENIG, OSP and more — you can even specify to have no coating whatsoever.

FR4 不仅具有良好的防火性能,而且热膨胀系数低——这意味着它在高温或低温环境下都不会发生太大的膨胀或收缩。这一点至关重要,因为如果 PCB 板发生过大的膨胀或收缩,板上的线路和元件很可能会损坏、开裂或断开。大多数 PCB 厂商都会提供多种厚度的 FR4 板,您可以根据应用需求选择合适的厚度和强度。

As well as being essentially fireproof, FR4 has a low thermal expansion coefficient — this means that it won’t expand or contract very much in hot or cold environments. This is important because if a PCB expands or contracts a large amount, then it is likely that traces and components on the board will be damaged, crack, or disconnect. Most PCB houses will offer a choice of thickness of FR4 boards, allowing you to choose a thickness and strength suitable for your application.

由于 FR4 是最常用的 PCB 材料,因此在设计 FR4 PCB 时无需考虑太多特殊因素或进行太多更改。如果您希望 KiCad 在使用 3D 查看器时显示目标板厚度,可以通过调整“电路板设置”中的介质层厚度值来进行更改。此对话框位于PCB 编辑器的“文件”>“电路板设置”中,然后您需要从列表中选择“物理堆叠”选项,并调整“介质层 1”厚度变量(图 8-2)。

As FR4 is the most common PCB material, there aren’t many special considerations or changes needed when designing a PCB for FR4. If you want to set up KiCad to display your target board thickness when using the 3D viewer, you can change this by adjusting the dielectric thickness value via the Board Setup. This dialogue is found at File > Board Setup in the PCB Editor, then you need to select the Physical Stackup option from the list, and then adjust the Dielectric 1 thickness variable (Figure 8-2).

图 8-2:改变“介质层 1”的厚度以改变 PCB 设计的整体厚度

摇摇晃晃

Wibbly wobbly

柔性PCB设计在现代电子产品中应用广泛,其中最常见的当属简单的柔性连接器。柔性连接器的优势显而易见,它们可以将系统中不同位置的元件或PCB模块连接起来。柔性连接器可以插入特定的夹紧插座,也可以直接焊接在铜焊盘上。它们能够折叠弯曲,从而实现复杂的PCB布局,而无需使用较大的排针或插座。

Flexible PCB designs are commonplace in modern electronics for many use cases. Probably the most common are simple flex connectors. These have obvious advantages, in that they can connect components or PCB modules in different locations in a system. Flex connectors can be inserted into specific clamping sockets or directly soldered onto copper pads. They have the benefit of being able to fold and bend around, allowing complex layups of PCBs which do not need larger header pins or sockets.

柔性PCB基板种类繁多,最常见的是聚酰胺薄膜。走线和焊盘的工作原理与普通PCB非常相似,都是由一层薄薄的铜构成。柔性PCB的设计可能相当复杂,许多PCB制造商都提供柔性PCB的定制层材料选项。这些柔性PCB也可能包含刚性部分,这意味着您必须提供能够区分不同基板的设计方案。

There are numerous types of flexible PCB substrate, with the most common being polyamide film. Traces and pads work in a very similar manner to any PCB, in that they are a thin layer of copper. Flexible PCBs can become quite complex to design for, and many PCB fabrication houses will have options for custom layer materials in flex PCBs. These can also include rigid sections, which means you must supply a design that can distinguish different substrates within it.

如果您计划使用这项技术,我们建议您阅读PCB制造厂商提供的所有相关指南,并直接与他们沟通,解释您的设计理念。它可能像设计常规PCB一样简单,只需像设计刚性PCB一样导出Gerber文件即可,但也可能存在一些特殊注意事项。

If you plan to use this technology, we’d recommend you read any guidance your PCB fabrication house has and to speak to them directly to explain your concept. It can be as straightforward as laying out a regular PCB design, exporting some Gerbers as you would with a rigid PCB, but there may be specific considerations.

铜的难题

铜箔厚度是指PCB上任意一点的铜箔厚度。它通常以盎司/平方英尺(oz/ft²)为单位,因此1oz/ft²的铜箔厚度比2oz/ ft²的要薄。铜箔厚度在PCB走线设计中至关重要,因为它会影响走线的深度。当考虑电路中某些部分可能通过的电流大小时,可能需要使用不同的走线宽度和铜箔厚度。同样,在更复杂的PCB设计中,当需要匹配走线长度时,走线的阻抗和射频特性以及走线尺寸都可能发挥作用。

Copper weight describes the thickness of copper at any given point on a PCB. It’s often expressed as ounces per square foot, so a 1oz/ft2 copper weight will be thinner than 2oz/ft2. Copper weight can be important in terms of designing PCB traces, as the weight affects the depth of the trace. Different trace widths and weights may need to be used when considering the amount of current that certain parts of a circuit may be passing. Similarly, track impedance and RF qualities of tracks may well come into play, as well as track sizes, when trying to match lengths of track in more complex PCB designs.

最常见的铜箔重量是 1 盎司或 2 盎司,许多 PCB 厂商都会提供这两种选择。如果您需要更精确的铜箔重量,一些 PCB 制造商可以通过在电路板上电镀或蚀刻额外的铜箔来提供定制的铜箔重量,但需要额外付费。

Most common copper weightings are 1oz or 2oz, and many PCB houses will offer these as a choice. If you require a precise copper weighting, it’s possible, at a price, for some PCB fabricators to offer more bespoke weight of copper by plating or etching extra material to or from the board.

图 8-3: KiCad 中的柔性天线设计

柔性PCB的一个典型应用是柔性天线。我们在网上找到一篇论文,其中包含一张双频2.4GHz和5GHz贴片天线的图片和尺寸,这引起了我们的兴趣,于是我们开始在KiCad中进行布局设计。我们首先在Inkscape中导入了设计所需的PDF源文件,但由于该文件使用了渐变填充,整个对象充满了节点,因此无法正确导出。如果这是一个位图图像,Inkscape的“位图描边”功能就能很好地解决这个问题,但由于它是矢量文件,该功能无法使用。不过,作为矢量图像,我们可以轻松地拖入垂直和水平参考线,并将它们对齐到PDF天线图的边缘(图8-4)。

A good use case for flex PCBs is a flexible antenna. We’d found a paper online with an image and dimensions for a dual-band 2.4GHz and 5GHz patch antenna, which piqued our curiosity, so we set about laying it out in KiCad. We began in Inkscape: we imported the PDF source we had for the design into Inkscape, but it had a gradient fill and therefore wouldn’t export correctly as the whole object was full of nodes. If this was a bitmap image, it would have been a good candidate for Inkscape’s Trace Bitmap function, but as it was a vector file, this wouldn’t work. However, as a vector image, it was straightforward to drag in vertical and horizontal guide lines and snap these to the edges of the PDF antenna drawing (Figure 8-4).

图 8-4:使用 Inkscape 中的辅助线手动描绘天线设计图

一旦我们有了天线每个部分的参考线,使用钢笔工具围绕该部分绘制连续线,将其闭合形成一个实体对象,就变得很简单了。

Once we had a guide line for every part of the antenna in place, it was a simple job to use the pen tool to draw a continuous line around the part, closing it to form a solid object.

柔性PCB可以弯曲,但多次弯曲后就会开始断裂。具体的断裂频率取决于制造商和具体设计。

Flexible PCBs can be bent, but over multiple bends, they will start to break. Exactly how often will vary between manufacturing houses, and specific designs.

为了延长PCB的使用寿命,在设计柔性PCB时,应避免在走线中使用90度直角,因为PCB弯曲时,这些尖角容易成为撕裂和故障的源头。虽然对于本设计而言,这并非一个主要问题,但我们可以通过选择天线对象,然后使用“路径效果”对话框应用“拐角”路径效果倒角选项(图8-5 )轻松地为其添加内部和外部径向倒角。最后,我们删除了原始导入的PDF文件,调整文档大小以适应天线设计,然后将其另存为SVG格式。

One thing you can do to prolong the life of the PCB is avoid using sharp 90-degree angles in traces when aiming for a flex PCB as, if the PCB is flexed, the sharp corners can be origin points for tears and failures. Whilst this is not a massive concern for this design, it was easy to add internal and external radial chamfers to the antenna object by selecting the object, then using the Path effects dialogue to apply the Corners path effect chamfer option (Figure 8-5). Finally, we deleted the original imported PDF, resized the document to fit the antenna design, and then saved it as an SVG.

图 8-5:使用Inkscape 中的“拐角”路径效果添加内部和外部倒角

在一个全新的 KiCad 项目中,我们忽略了创建原理图并将元件与原理图符号关联的常规工作流程,直接进入了 PCB 编辑器。无需原理图,即可在 PCB 编辑器中直接添加元件和创建走线。对于更复杂的项目,我们不建议采用这种方法,因为您无法检查连接性或创建网络连接,但对于像这样的小型简单项目来说,这种方法非常便捷。

In a new KiCad project, we ignored the usual workflow of creating a schematic and associating parts to schematic symbols and went straight to the PCB Editor. You can directly add components and create traces in the PCB Editor with no schematic in place. For a more complex project, we wouldn’t recommend this approach, as you have no means of checking connectivity or creating net connections, but for small simple projects like this, it’s easy.

我们导入了天线SVG文件,并确保将其导入到正面铜层(F.Cu)上。然后,我们使用“添加封装”工具添加了两个小型SMD焊盘。我们将这些焊盘放置在原始设计中天线图案的相应位置。由于没有原理图,这些焊盘没有网络连接,它们将直接连接到我们刚刚放置的大型铜天线图案上。当然,这些焊盘上没有阻焊层,因此您可以焊接连接同轴电缆。接下来,只需快速绘制另一个SVG文件作为天线的轮廓,我们使用Inkscape绘制,但您也可以使用KiCad绘制。将轮廓导入到边缘切割层后,您的设计就完成了。

We imported the antenna SVG, making sure to import it onto the Front Copper layer (F.Cu). We then used the Add a Footprint tool to add two small SMD pads. We positioned these on the points in the antenna design that the original design had indicated. With no net connections due to no schematic, these pads will be directly connected to the large copper antenna design that we just placed, but of course, the pads will have no solder mask over them, allowing you to solder on a connecting coaxial cable. All that remains is to then quickly draw another SVG for the outline of the antenna, which we did in Inkscape, but you could just draw in KiCad. With the outline imported to the edge cuts layer, you have a completed design.

为了完成设计制作,我们使用了 OSH Park,他们提供柔性 PCB 板服务。OSH Park 的一个优点是无需生成 Gerber 文件上传——您可以直接将 KiCad PCB 文件上传到网站进行预览和订购。方便的是,项目文件和 Gerber 文件通常不会指定基板或厚度,因此您无需在 KiCad 中指定超薄柔性板设计。但是,如果您需要在宣传中使用 KiCad 设计的渲染图,或者需要将电路板的 3D 模型导出到其他 CAD 程序中使用,那么您可能仍然需要在 KiCad 中精确建模。

To get the design fabricated, we used OSH Park which has a flex PCB offering. One of the nice features of OSH Park is that you don’t have to produce Gerber files to upload — you can upload your KiCad PCB file directly to the website for previewing and ordering. Conveniently, project files and Gerber files don’t particularly specify the board substrate or thickness, so you don’t need to specify a thin flex board design in KiCad. However, you might want to model the board accurately in KiCad, especially if you are using either renders of the KiCad design in promotion or if you are exporting the board 3D model for use in other CAD programs.

您可以使用PCB编辑器中的电路板设置对话框和“物理堆叠”选项卡来模拟柔性电路。您的PCB制造商会提供其柔性PCB产品各层厚度的数据,您可以利用这些数据在电路板设置中设置厚度。如果您只需要一个与您的柔性设计足够接近的PCB视图,您可以简单地调整电路板的主要厚度,方法是将材料更改为聚酰胺,并将该层的厚度设置为0.0102毫米(这是OSH Park柔性聚酰胺层的厚度),如图8-6所示。然后,您可以使用“自定义颜色”选项将顶层和底层阻焊层的颜色设置为透明,方法是将不透明度降低到零。这样,在3D查看器中,您就可以得到一个合理的柔性PCB近似图(图8-7)。

You can use the board setup dialogue and the Physical Stackup tab in the PCB Editor to emulate a flex circuit. Your PCB fabrication house will have data about all the thicknesses of each layer of their flexible PCB offerings and you can use this to set thicknesses in the board setup. If you just need a close enough PCB view that looks like your flex design, you can simply adapt the major thickness of the board by changing the material to Polyamide and setting the thickness of that layer to 0.0102mm (this is the OSH Park flex polyamide layer thickness), as in Figure 8-6. You can then set the colours of the top and bottom solder mask layers to transparent by reducing the opacity to zero using the Custom colour option. This, in the 3D viewer, will then give you a reasonable approximation of a flex PCB (Figure 8-7).

图 8-6:通过设置电路板材料、介质层厚度和阻焊层颜色,您可以在 KiCad 3D 查看器中模拟柔性 PCB。
图 8-7:柔性电路的 3D 渲染图

坚如磐石

Hard as nails

通常,PCB制造商会提供用于PCB的金属基板,常见的有铜或铝。当需要快速散热时,这些基板非常有用。例如,对于温度传感器模块,如果既要保证传感器的精度,又不希望电路板吸收过多热量,那么铝基板通常是一个不错的选择。金属基板PCB的另一个应用场景是需要PCB本身作为散热器。例如,我们委托JLCPCB制造并组装了一些1瓦的LED模块(图8-8)。

Often, PCB manufacturers offer metal substrates for PCBs, commonly copper or aluminium. These substrates can be useful when you need to dissipate heat quickly through a system. Often, aluminium substrates can make sense for temperature sensor modules where you want the sensor to be accurate but don’t want the board to soak up heat. Another application for metal substrate PCBs is where you want the PCB to act as a heatsink. For example, we had JLCPCB make and assemble some 1-watt LED modules (Figure 8-8).

这些1瓦的LED灯珠会产生相当多的热量,为了延长其使用寿命,最好配备散热片。LED灯珠背面有一个与电路板连接的大型导热垫,而铝板背面则是裸露的金属。这可以起到LED模块的散热作用,从而降低温度。需要注意的是,铝和铜基板的PCB板在受到压力或负载时可能会弯曲。事实上,当您收到成片的铝基板PCB板时,如果不弯曲PCB板,就很难将其取下。

Running at 1 watt, these LEDs generate a reasonable amount of heat and, to promote their long life, it’s useful to have some kind of heatsink. The reverse side of the LED has a large thermal pad which connects to the board, and the reverse of the aluminium board is bare metal. This acts as a heatsink for the LED module and the temperature is reduced. One thing of note is that aluminium and copper substrate PCBs can be bent if they are put under pressure or load. In fact, when your aluminium PCBs arrive in panels, it can be quite hard to remove them without bending the PCB.

填补孔洞

过孔,即连接PCB不同层的小型镀通孔,可以采用不同的表面处理方式。对于许多项目来说,PCB制造商的默认处理方式就足够了,但了解一下常见的处理选项也很有必要:

Vias, the small plated through-holes that connect different layers of the PCB can be finished in different ways. For many projects, the PCB fabrication house default will be fine, but it’s worth looking at the common options offered:

  • 覆盖式过孔表面覆盖有阻焊层,因此焊料不会粘附在其上。根据过孔尺寸的不同,孔内是否填充焊料取决于其大小。覆盖式过孔的另一个优点是,它可以降低电路板在组装成产品或搬运过程中发生意外短路的风险。
  • Tented vias are covered with the solder mask, so no solder would stick to them. The hole may or may not be filled, depending on the size of the via. Another benefit of tenting is that you reduce the risk of unintended shorts when boards are being assembled into products or being handled.
  • 未覆盖的过孔没有覆盖物,因此其表面处理方式与裸露的焊盘和其他铜部件相同。虽然这可能不会造成问题,但存在意外焊接到过孔或导致短路的风险。
  • Un-tented vias have no covering, so are finished in the selected surface finish in the same way as exposed pads and other copper features. Whilst this may well be fine, there is a risk of accidentally soldering to vias or for short circuits.
  • 堵塞的过孔可以通过几种不同的方式填充,或者您可以选择其中一种。一种方法是用阻焊层填充过孔;另一种方法是用环氧树脂填充过孔。一些制造商可能只能填充特定直径的过孔,或者,一些PCB制造商可以提供定制方案,您可以要求填充所有特定直径的过孔。堵塞过孔的好处在于,过孔不会意外地被焊料或其他导电材料填充。
  • Plugged vias are filled in a couple of different ways, or you may have a choice. One way is to fill the via with solder mask; another is to fill the via with epoxy resin. Some manufacturers may only be able to fill vias up to a certain diameter or, indeed, some PCB houses can offer custom approaches where you can ask for all vias of a certain diameter to be filled. The benefit of plugging vias is that the via can’t accidentally become filled with solder or other conductive material.
  • 导电塞孔并非最常用的选择,但一些PCB制造商会用导电材料填充过孔。这可以提高过孔的通电流。然而,导电填充物的热膨胀系数可能与其他电路板材料不同,导致轻微弯曲,进而引发潜在的故障。例如,JLCPCB提供用导电铜填充环氧树脂填充过孔的方案。
  • Conductive plugged vias are not the most common choice, but some PCB houses can fill vias with conductive material. This can increase the amount of current the via can pass. There are trade-offs in that the conductive filler may thermally expand at different rates than the other board materials, causing small flexes leading to potential failures. As an example, JLCPCB offers the option to fill vias with conductive copper-filled epoxy.

FR4、柔性基板和铝基板并非仅有的选择。对于高速设计、微波频率设计或医疗器械等特殊应用,还有其他基板可供选择,例如罗杰斯基板、聚四氟乙烯基板、特氟龙基板和铜芯基板。这些都是特殊材料,本文不做赘述。

FR4, flexible, and aluminium are not the only options. With high-speed designs, designs running at microwave frequencies, or very special applications like medical devices — there are other substrates available. Rogers, PTFE, Teflon, Copper Core. These are specialist materials, and we won’t look at them here.

图 8-8:小型铝制 LED 模块

第九章

Chapter 9

寻找PCB制造商

Finding a PCB manufacturer

为您的项目挑选最佳加工商

Picking the best fabricator for your project

上一章我们探讨了各种PCB制造商和PCBA服务商提供的不同基板和其他硬件选项。本章我们将概述可提供的服务范围,并探讨一些公司在开展PCB项目时需要您提供哪些信息。我们还会提及一些我们在使用某些服务时遇到的令人费解的问题。

In the last chapter, we looked at the different substrates and other hardware options that are available across a range of PCB fabricators and PCBA services. In this chapter, we are going to generally look at the range of services that are available and look at what some of the companies need from you to make your PCB projects. We’ll also mention a few of the quirks we’ve found in some services that had us scratching our head.

图 9-1:小型 PCB 标尺项目给 PCB 服务带来了一些有趣的挑战。

有很多成熟的公司能够生产高质量的PCB,无论是否需要组装。然而,每家公司的规格和公差都各不相同。事实上,在比较或寻找合适的PCB制造服务时,这通常是一个很好的切入点。你需要问自己的问题包括:我们需要的最小间距和走线宽度是多少?最小孔径是多少?我们需要多高的精度?

There are many well-established companies capable of creating quality PCBs with and without assembly. However, they each have different specifications and tolerances. In fact, that’s often a good place to start when comparing or looking for a service to make your project. Questions to ask yourself include: what minimum clearances and track widths do we need? What is the smallest hole diameter? How accurate do we need things?

在 OSH Park 网站上,他们提供了大量与其服务相关的文档(图 9-2)。“钻孔规格”页面详细列出了最小和最大孔径、环形孔尺寸以及过孔电镀规格。请注意,所有这些规格在 OSH Park 的不同服务中均有所不同,例如,双层、四层和六层板的规格就有所不同。OSH Park 网站上列出的最小走线宽度规格为 0.006 英寸,标准双层板的间隙为 0.006 英寸,四层板的间隙则减小到 0.005 英寸(经常会看到以千分之一英寸为单位的限制,因为显然,只要你足够努力,就可以同时使用公制和英制单位)。

Over on OSH Park, they have a great collection of documents relating to the services they provide (Figure 9-2). The Drill Specs page details the minimum and maximum hole sizes, sizes for annular rings, and the via plating specification. Be aware that all these specifications are different across OSH Park’s various services, changing, for example, between the two-, four-, and six-layer options. The minimum track width specification on the OSH Park site is listed as 0.006", with 0.006" clearance on the standard two-layer boards, moving down to 0.005" in the four-layer board offerings (it’s common to see limits given in thousandths of an inch because, apparently, you can have both metric and imperial at the same time if you try hard enough).

您可以在hsmag.cc/oshparkrules 的OSH Park KiCad 设计规则页面上找到此内容和所有其他详细信息。

You can find this and all the other details on the OSH Park KiCad Design Rules page at hsmag.cc/oshparkrules.

图 9-2: OSH Park PCB 服务的技术细节

如果您对 OSH Park 的服务有任何疑问,他们的沟通记录非常出色。您可以发送邮件至支持邮箱,他们会尽快回复并提供建议。我们甚至曾请 OSH Park 团队打开 KiCad 项目文件,他们不仅解决了问题,还耐心指导我们如何解决。许多服务都提供在线聊天平台(图 9-3)。当您与服务方沟通遇到的问题或挑战时,这些平台会非常有用。

If you have questions about the OSH Park services, they have an excellent track record in communication. You can email the support email address, and they will get back to you offering advice. We have even had the OSH Park team open a KiCad project file, and they have fixed problems and then taken the time to teach us solutions. Many of the services offer online chat portals (Figure 9-3). These can be useful when trying to negotiate problems or challenges with a service.

图 9-3: JLCPCB 的聊天门户

不同的PCB制造商会将相关信息放在不同的位置。另一家PCB服务商DirtyPCBs则将规格和公差信息集中放在其“关于我们”页面(图9-4)。他们列出了两层和四层板的最小走线宽度和间距均为0.006英寸,并列出了其他规格和公差。DirtyPCBs的服务定位是精简型服务,注重价格低廉,因此没有在线聊天功能,联系该公司咨询问题也比较困难。如果您遇到此类问题,不妨尝试使用搜索引擎,查找论坛上关于该服务的讨论,以期找到所需的答案。

Different PCB manufacturers put the information in different places. Another PCB service, DirtyPCBs, bundle their specifications and tolerances information on their About page (Figure 9-4). They list a 0.006" minimum track width and clearance across both their two- and four-layer boards and cite their other specifications and tolerances. The DirtyPCBs service was designed as a minimal service with its emphasis on cheap, therefore, it has no chat service, and it’s difficult to contact the company to ask questions. If you have challenges here, it can be a better option to use search engines and find forum conversations about the service to try and get the answers you need.

图 9-4: DirtyPCBs PCB 规范位于一个篇幅较长的“关于我们”页面中。

当然,本书中我们大量使用了JLCPCB的产品。JLCPCB在其 “产品特性”页面(图9-5)上提供了详尽的规格列表。他们的PCB最多可提供20层铜层,双层PCB的走线宽度和间距默认最小值为0.005英寸,四层及以上PCB的走线宽度和间距则可达0.0035英寸。

We have, of course, used JLCPCB a fair amount in this book. JLCPCB have an exhaustive list of their specifications over on their Capabilities page (Figure 9-5). They can offer up to a whopping 20 copper layers in their PCBs, with track widths and clearances a default minimum of 0.005" in the two-layer offering, moving to 0.0035” for four-layer options and more.

图 9-5: JLCPCB 的规格说明可在其“能力”页面找到。

PCBWay 也提供类似的规格。这项服务的优势在于,他们可生产的 PCB 最大尺寸为 1100 × 500mm,而 JLCPCB 等公司的最大尺寸仅为 500 × 400mm。值得注意的是,PCBWay 的操作方式与其他服务相比略有不同:您需要先指定电路板型号和尺寸,并将其添加到购物车,然后再上传 Gerber 文件。

Similar specifications are available from PCBWay. An advantage of this service is the maximum dimensions of PCBs they can fabricate are 1100 × 500mm, whereas, for example, JLCPCB are 500 × 400mm. One thing of note about PCBWay is that you specify the board and the board dimensions and add it to your shopping cart prior to uploading Gerbers, which can seem slightly counter-intuitive compared to other services.

对于所有这些服务,如果您想了解具体细节,建议您使用聊天功能或电子邮件与他们联系。

With all these services, it’s worth contacting them using the chat function or emailing if you want to check specifications.

规则

Rules Rule

在开发PCB项目时,如果您已选定特定的制造服务商,可以通过设置电路板的设计规则来确保电路板设计的兼容性,使其与该服务商相匹配。设计规则位于我们在第8章“不同基板”中提到的“电路板设置”窗口下用于设置不同基板的物理叠层特性。

While developing a PCB project, if you have a particular fabrication service in mind, you can ensure your board design’s compatibility by setting up the Design Rules for your board to match the service. The Design Rules is nested under the Board Setup window we used in Chapter 8, Different substrates to set up the different physical stackup characteristics for different substrates.

在PCB编辑器中,导航至“文件”>“电路板设置” ,然后打开名为“设计规则”的下拉菜单。在第一部分“约束”中,您可以设置最小间距、最小走线宽度以及与铜区域相关的其他限制。您还可以调整最小过孔尺寸、孔径和间距,以及丝印层上文本对象的最小尺寸。

In the PCB Editor, navigate to File > Board Setup and then open the drop-down menu labelled Design Rules. In the first section, Constraints, you can set up limits for the minimum clearances, minimum track widths, and other limits relating to the copper regions. You can also adjust the minimum via sizes, hole sizes, and clearances, and the minimum dimensions for text objects on the silkscreen layer.

“设计规则”下拉菜单中的下一个选项是“预定义尺寸”选项卡。本书前面部分已经使用过它来设置项目的走线宽度。不过,需要提醒的是,您可以在项目开始时设置走线宽度,同时考虑目标PCB服务商的任何限制或约束。此外,请注意,您可以从之前的项目中导入设置——如果您要根据特定的PCB服务规范设置项目,这将非常有用。

The next item down in the Design Rules drop-down menu is the Pre-defined Sizes tab. You used this earlier in the book to set track widths for projects. However, as a reminder, you could set this up at the beginning of a project whilst considering any limitations or constraints your target PCB service has. Also, notice that you can import the settings from a previous project — this is helpful if you set up a project for a particular PCB service specification.

跳转到“设计规则”下拉菜单底部,您可以看到“违规严重程度”部分。此部分设置了当项目规则被违反时,设计规则检查器(DRC) 工具的响应方式。首先要提醒的是,在将任何规则设置为“忽略”之前,请务必仔细考虑。虽然对于当前项目而言,您可能并不在意其中的一些问题,但在其他情况下或项目中,被忽略的错误可能会造成严重后果。

Jumping to the bottom of the Design Rules drop-down menu, you can see the Violation Severity section. This section sets up how the Design Rule Checker (DRC) tool responds if any of the rules set for a project are broken. As a primary word of warning, think very carefully before setting any of these to ‘ignore’. It may well be that for a current project you don’t mind some of these issues, but it’s possible under different circumstances or projects, an ignored error could be critical.

返回PCB编辑器窗口,要在项目的任何阶段运行DRC,您可以单击“显示设计规则检查器”窗口工具图标,或者从“检查”下拉菜单中选择“设计规则检查器” 。窗口打开后,您可以单击“运行DRC”按钮,使PCB符合已定义的设计规则。

Back in the PCB Editor window, to run the DRC at any point in your project, you can either click the Show the design rules checker window tool icon or you can select Design Rules Checker from the Inspect drop-down menu. Once the window is open, you can then click the Run DRC button for the PCB to be checked against the defined design rules.

收到错误或警告并不总是意味着您的PCB项目无法正常工作,它们只是表明某些设计规则未得到遵守。规则并非必须遵守,但检查哪些规则被违反始终是有益的,这样可以确保所有违反的规则都是有意为之。例如,在标尺PCB设计中,由于标尺位于切割边缘几何形状的上方,我们遇到了许多丝印错误;此外,由于我们使用的安装孔封装的庭院区域重叠,我们也遇到了许多庭院错误。所有安装孔之间的实际距离都超过了最小间隙,因此这两类问题都无关紧要——尽管如此,检查一下仍然值得。

Getting an error or a warning doesn’t always mean that your PCB project isn’t working, but they are simply indications that there is something that hasn’t met the design rules. Rules don’t always have to be followed, but it’s always good to check which rules are broken so you can be sure that any that are broken are broken intentionally. For example, on the ruler PCB design, we got numerous silkscreen errors as the ruler sat over the edge cut geometry, and we also got lots of courtyard errors where the courtyard areas of the mounting hole footprints we had used had overlapped. All of the actual distances between the mounting holes were over the minimum clearance from each other, so neither of these sets of issues mattered — it was worth checking, though.

运行 DRC 时,会在您的 PCB 设计上添加红色小箭头或标记,突出显示问题所在。即使关闭 DRC 窗口,这些标记仍会保留在您的设计上。在 DRC 窗口关闭的情况下,如果您选择某个标记,该标记所对应的问题将显示在 PCB 编辑器底部的工具栏中。您可以重新打开 DRC 窗口,并使用相应的按钮删除单个或所有标记。当然,如果您不对 PCB 设计进行任何更改就再次运行 DRC,则已删除的标记将被重新添加。

The DRC, when run, will add small red arrows or markers on your PCB design, highlighting where the issues are located. If you close the DRC window, the markers remain on your design. When selecting a marker when the DRC window is closed, the issue that the marker relates to will be shown in the lower toolbar on the PCB Editor. You can reopen the DRC window and delete single markers or all markers using the relative buttons. Obviously, if you don’t make changes to the PCB design and run the DRC again, removed markers will be replaced.

统治者统治

Rulers Rule

制作PCB尺几乎是PCB制作圈的一项必备技能。它可以是一个简单实用的工具,一张不错的名片,甚至可能还有其他功能。我们的一位作者(Jo)对模型火箭和高功率火箭很感兴趣,所以他制作了一把带有精确孔洞的尺子,可以把笔插进去。然后,你可以把笔尖对准0或100毫米的刻度,画出与常见火箭发动机直径或Estes火箭箭体直径相匹配的圆圈。这对于临时制作卡纸或轻木火箭部件非常方便。虽然找PCB制造商来做这件事可能看起来有点奇怪,但这确实是一种非常经济实惠的获得高精度二维设计图的方法。

Making a PCB ruler is almost a rite of passage in the PCB-making communities. They can be a simple, useful tool, a good business card, or perhaps even perform some extra function. One of your authors (Jo) has an interest in model and high-power rocketry, so he made a ruler which has some accurately placed holes in it, into which you can place a pen. You can then pin the hole at the 0 or 100mm marker and draw circles that match common rocket motor diameters or common Estes rocket body tube diameters. Handy for impromptu cardstock or balsa rocket component-making. It might seem strange to use a PCB manufacturer for this, but it’s a very affordable way of getting very accurate 2D designs made.

在 KiCad 中创建 PCB 标尺时,一个略微棘手的问题是如何绘制刻度线,从而为标尺赋予测量图形元素。您可以结合 KiCad 的 SVG 导入功能,使用优秀的开源软件 Inkscape 来解决这个问题。

One slightly tricky aspect of creating a PCB ruler in KiCad is how to draw a graduated line to give the ruler its measuring graphic element. You can use the excellent open source Inkscape to solve this in combination with KiCad’s SVG import abilities.

在 Inkscape 中,使用钢笔工具绘制一条直线,并调整高度和宽度设置,使其长度与所需的刻度线段长度相同。例如,对于紧凑型标尺 PCB,您可以选择 100 毫米的长度。接下来,选中该直线,然后单击“路径”>“路径效果”。“路径效果”对话框应在屏幕右侧打开——对话框顶部应该有一个搜索栏。输入“标尺”,然后选择搜索结果中出现的“标尺路径效果”。这将打开“标尺路径效果”对话框。将单位设置为毫米,并将标记距离设置为1。这样,就会沿着直线添加间隔 1 毫米的刻度线。接下来,您可以设置较长刻度线的主刻度长度和较短刻度线的次刻度长度。最后,将主刻度步长设置为10。现在,您应该得到一个每隔 10 毫米就有一个较长刻度线的标尺图形。

In Inkscape, draw a straight line using the pen tool and use the height and width settings to set it to the length of the ruled section you require. For a compact ruler PCB, you could go with a 100mm length. Next, select the line and then click Path > Path Effects. The Path Effects dialogue box should open on the right-hand side of the screen — there should be a search bar at the top of this dialogue. Type in ‘ruler’ and select the Ruler Path Effect that appears in the results. This, in turn, should launch the Ruler Path Effects dialogue. Set the Units to mm and then set the Mark Distance to 1. This should then add a graduation line one millimetre apart along your line. Next, you can set the length of the major length for the longer graduation lines and the minor length for the shorter lines. Finally, set the Major Steps to 10. You should now have a ruler graphic with a longer marker every 10mm.

您可以使用 KiCad 在标尺图形上添加文字来标记数字,但使用 Inkscape 的对齐和分布工具可以轻松地将一行文本标签与标尺对齐。然后,您可以使用文档属性将文档调整为设计尺寸,并将其保存为 SVG 文件,以便将其导入 KiCad PCB 编辑器中的丝印层。转到“文件”>“导入图形”,然后在对话框中找到 SVG 文件,将其设置为导入到正确的图层(在本例中为正面丝印层),并确保缩放比例设置为1。建议将 PCB 编辑器网格设置为1 毫米,以便您可以将其他元素与标尺设计很好地对齐。最后,您可以偷懒,保留标尺图形中的基线,然后使用边缘切割几何体将其移除——这样可以确保丝印标尺线延伸到 PCB 的边缘。但是,您可以在 Inkscape 中重新删除原始线条。

You could use KiCad to add the text to mark the numbers on your rule graphic, but it’s easy to use Inkscape’s align and distribute tools to bring a line of text labels into alignment with the ruler. You can then resize the document using document properties to the size of the design and save it as an SVG to be imported to the silkscreen layer in KiCad in the PCB Editor. Go to File > Import Graphics, and then, in the dialogue, navigate to the SVG, set it to import to the correct layer (in this case, the front silkscreen), and make sure the scaling is set at 1. It’s worth setting the PCB Editor grid to 1mm so that you can align other elements to the ruler design well. Finally, you can be lazy and leave the baseline in the ruler graphic and then used the edge cuts geometry to remove it — this ensures that the silkscreen ruler lines run right to the edge of the PCB. However, you can remove the original line back in Inkscape.

应用路径效果后,您可以选择整个标尺图形,然后使用“路径”>“对象转路径”将路径效果转换为常规路径。接下来,使用节点选择工具,您可以选择底线并将其删除。由于难以直接选中基线末端的节点,您可以放大视图,然后拖动基线到两个刻度线节点之间,使线条弯曲。线条弯曲后,单击并将其删除。

When you have your path effect applied, you can select the entire ruler graphic and then use Path > Object to Path to convert the path effect into regular paths. Then, using the node selection tool, you can select the bottom line and delete it. As it’s difficult to grab the nodes at the end of the baseline, you can zoom in and then bend the line away by dragging the baseline in between two of the graduation line nodes. Once the line is bent away from the graduations, you can click it and delete it.

深入探索

Diving deeper

OSH Park 在支持和推广开源项目方面有着卓越的记录,其标志性的紫色阻焊层涂装在众多创客/硬件黑客项目中都非常醒目。然而,OSH Park 经常被推荐为服务商的主要原因之一,或许在于用户可以直接将 KiCad PCB 文件上传到他们的网站——无需再经历创建兼容 Gerber 文件的过程。这使得该服务非常易于使用。如果您是在 KiCad 新版本发布后阅读本文,您可能会发现 OSH Park 网站服务需要一些时间才能完全兼容,但在此期间,您也可以像其他服务商一样上传 Gerber 文件的 zip 压缩包。OSH Park 关于 Gerber 文件设置和要求的指南可在hsmag.cc/Gen_Gerbers上找到。

OSH Park have an excellent track record in supporting and promoting open source projects, and they have an iconic purple solder mask finish which is very visible across lots of maker/hardware hacker projects. However, probably one of the main reasons that OSH Park have often featured as a service is that you can directly upload KiCad PCB files to their website — you don’t have to go through the process of making compatible Gerber files. This makes the service easy to use. If you are reading this after a new milestone version of KiCad has been released, you might find that it takes a little while for the OSH Park website service to become compatible, but you can also upload a zip file of Gerbers in the same way as other services in the interim. OSH Park’s guidance on Gerber set up and requirements is available at hsmag.cc/Gen_Gerbers.

除了标准的 OSH Park 紫色电路板之外,还有 After Dark 版本(黑色基板和透明阻焊层)、更轻的 0.8mm 厚度电路板(配备更厚的 2oz 铜层)以及柔性电路板等选项。虽然它们质量上乘,但对于小型 PCB 设计来说,价格却非常实惠。最后,OSH Park 的沟通服务也十分出色。如果您需要提交工单咨询问题,他们会竭尽全力提供帮助。

Beyond the standard OSH Park purple offering, there are options for the After Dark finish (black substrate and a clear solder mask), a lighter 0.8mm board with a heavier 2oz copper layer, and a flex option. Whilst they offer good quality, they are incredibly affordable when working with smaller PCB designs. Finally on OSH Park, they are excellent at communications. If you need to raise a ticket to ask a question, they go above and beyond.

不同的加工商对您上传的文件及其格式有不同的要求。我们注意到,DRL(钻孔参考线)文件容易出现问题。在 KiCad 中,您可以创建一对 DRL 文件,一个包含未镀通孔,另一个包含镀钻孔;或者您可以将这两个文件合并为一个。JLCPCB 要求这些文件成对提供,而如果您将包含两个独立 DRL 文件的 Gerber 文件上传到 OSH Park,您会收到错误消息,但 OSH Park 会自动在线合并这两个文件并解决问题。

Different fabrication houses have different needs around the files and file formats that you upload. One area we have noticed creating issues is the DRL or drill files. In KiCad, you can create either a pair of DRL files, one containing the non-plated through-holes and another containing the plated drill holes, or you can merge these two files into one. JLCPCB wants these files supplied as a pair, whereas if you upload Gerbers with two separate DRL files to OSH Park, you get an error message, but it conveniently will merge the two files online and solve the issue for you.

有些加工商要求提供钻孔文件,即使PCB设计中并没有钻孔。这在我们第八章“不同基板”中设计柔性PCB天线示例时引发了一个有趣的问题。尽管设计中没有钻孔,我们仍然导出了Gerber文件和DRL文件——这仅仅是因为我们想将Gerber文件上传到不同的服务商处,查看渲染效果并获取报价。

Some fabrication houses want there to be drill files even if the PCB has no drill holes in the design. This caused an interesting issue when we designed the flex PCB antenna example in Chapter 8, Different substrates. We exported the design Gerbers and DRL files even though the design contained no drilled holes — this was just because we wanted to upload the Gerbers to a range of services to see how they rendered and get quotes.

使用 JLCPCB 时,当我们上传柔性天线设计的压缩 Gerber 文件后,预览会忽略边缘切割几何形状(图 9-6),导致设计的圆角错误地消失,电路板显示为直角。与在线客服沟通后,他们确认可以看到边缘切割层,并保证如果我们下单,电路板会正确切割。

With JLCPCB, when we uploaded the zipped Gerber file for the flex antenna design, the preview would ignore the edge cuts geometry (Figure 9-6), so the curved corners of the design would incorrectly disappear, and the board would appear as having square edges. Chatting to the online chat service, they confirmed that they could see the edge cuts layer and assured us that if we placed the order, the board would be cut correctly.

图 9-6: JLCPCB 上的边缘切割几何问题

我们尝试调整 Gerber 文件,并在 KiCad 论坛上发帖讨论这个问题。似乎其他人从该项目生成 Gerber 文件后,在 JLCPCB 网站上都能正确渲染。我们发现的区别在于他们没有包含任何钻孔文件。重新上传不带钻孔文件的文件后,电路板的轮廓和边缘切割几何形状都能正确渲染。在此过程中,我们发现 OSH Park 没有这个问题,上传后电路板渲染正常。

We tried playing around with the Gerbers and we also posted the issue on the KiCad forum for discussion. It seemed that others generating their own Gerbers from the project would get a correct render on the JLCPCB site. The difference we spotted was that they weren’t including any drill files. Re-uploading without drill files and the correct board outline and edge cut geometry rendered correctly. As part of this process, we discovered that OSH Park didn’t have this issue and rendered the board correctly at upload.

这个故事告诉我们,Gerber 文件并非标准格式,所以一定要检查你需要什么,如果发现问题,要做好与 PCB 制造商沟通的准备。

The moral of this particular story is that Gerbers aren’t standard, so be sure to check what you need, and be prepared to talk to the PCB manufacturer if things don’t look right.

我们在考察不同的PCB制造服务时,还遇到了与空层相关的另一个问题。将设计上传到PCBWay时,虽然渲染结果正确,但上传过程却会报错,因为铜层的Gerber文件中没有铜(图9-7)。显然,这对于PCB来说非常不寻常,因为铜通常是连接元件和其他部件的导电层。这个标尺项目表明,如果PCB制造工艺更加艺术化,可能会给制造厂带来麻烦。

We had another issue relating to empty layers when looking at different fabrication services. When uploading the design to PCBWay, although it rendered correctly, it would throw an error with the upload because the Gerber file for the copper layers contained no copper (Figure 9-7). Obviously, this is very unusual for a PCB as copper is usually the conductive layer connecting components and more. The ruler project shows that with a more artistic use of PCB fabrication, it’s possible to cause headaches for fabrication houses.

图 9-7: PCBWay 渲染的标尺项目

最近我们在向JLCPCB服务部门提交铝基板LED模块项目时遇到了一些问题。我们在JLCPCB元件库中找到的1瓦COB LED,其数据手册上的图示显示,两个半对称的扁平SMD引脚连接器上标有极性标记。我们之前见过这种LED——它们的金属连接器上蚀刻有正负极标记。

We had a problem with a recent project when submitting the aluminium substrate LED module project to JLCPCB services. The 1-watt COB LED we had identified in the JLCPCB parts library had a diagram on the datasheet of the LED which had polarity markings on the two semi-symmetrical flat SMD pin connectors. we’d seen these LEDs in real life — they have an etched - and + in these metal connectors.

当我们将设计稿上传到JLCPCB网站时,网站上渲染的PCB板上元件已正确放置,但JLCPCB提供的LED 3D模型没有极性标记。我们当时认为这样是正确的,而且由于订购数量不多,LED本身体积较大,即使到货后发现极性错误,更换起来也不会太麻烦。下单后,订单流程暂停,JLCPCB联系我们讨论并确认LED的极性。我们不得不指出,这是他们3D模​​型的问题,导致无法判断LED的旋转方向是否正确(图9-8),他们的工程师只有亲自查看包装后才能确定。最终,铝箔LED PCB的生产是正确的。

When we uploaded to JLCPCB, the website rendered the PCB with the components placed and the JLCPCB 3D model of the LED had no polarity markings. we presumed it would be correct, and as only ordering a small number and the LED is a large part, it wouldn’t be too onerous to swap them around if they arrived incorrectly. After ordering, the process was halted, and JLCPCB contacted us to discuss and check the polarity of the LED. We had to point out that it was an issue with their 3D model that meant it was impossible to tell if it was rotated correctly (Figure 9-8), and an engineer at their end would only be able to tell when they physically went and looked at the package. In the end, the aluminium LED PCBs were correctly manufactured.

图 9-8: JLCPCB 上 LED 的修正渲染图

与任何 PCB 服务商合作的主要经验是,大多数事情都可以通过良好的沟通来实现,而良好的沟通,再加上物理规格,正日益成为选择使用哪家服务商的重要决定因素。

The main takeaway point for working with any PCB service is that most things are achievable with good communication, which increasingly becomes, in combination with the physical specifications, a valuable deciding factor in choosing which service to use.

第十章

Chapter 10

制作智能步进电机

Making a smart stepper motor

扩展RP2040电路,使其包含电机驱动器

Extend the RP2040 circuit to include a motor driver

Urumbu 是麻省理工学院的 Neil Gershenfeld 提出的一种机械概念,旨在简化多轴机器(例如 3D 打印机)的制造流程。目前主流的做法是将 G 代码逐行输入控制器,控制器再驱动各个步进电机,从而移动相应的轴。这套系统虽然可靠,但它源于并行处理能力稀缺且成本极其昂贵的时代。

Urumbu is a mechanical concept created by Neil Gershenfeld of MIT to simplify the process of creating multi-axis machines (such as 3D printers). The current go-to standard for is to feed Gcode line by line to a controller. This, in turn, drives the individual stepper motors to move the relevant axis. It’s a solid system, but it harks from an era where parallel processing capabilities were rare and incredibly expensive.

图 10-1:已完成的 PCB 连接到 NEMA 17 步进电机

Urumbu致力于简化机器制造流程,降低成本和复杂性。简而言之,它主要使用步进电机(或理论上的其他执行器),并集成嵌入式微控制器,使其能够直接通过USB接口运行。这意味着,理论上可以避免使用G代码。

Urumbu is interested in streamlining the making of machines, reducing both the cost and the complexity. In simplified terms, it essentially uses stepper motors (or theoretically other actuators) that have been adapted with an embedded microcontroller to run directly via USB. This means that, potentially, you can sidestep using G-code.

想象一下,构建一台机器,你可以通过参数化方式定义输出对象,脚本可以直接计算形状的几何形状,并直接控制连接到便捷 USB 集线器的快速成型机。图 10-2展示了一个 Urumbu 式控制器的示例。本章不会涵盖所有内容——它只会探讨如何构建一个用于控制步进电机的 PCB——但你可以在hsmag.cc/urumbu上找到更多信息。你还可以浏览 Fab Lab 的资料库,在那里你可以找到使用 Urumbu 方法的项目,例如这个出色的指向机器:hsmag.cc/point

Imagine building a machine where you parametrically define the output object, and the script directly calculates the geometry of the form and directly controls the rapid prototyping machine connected to a convenient USB hub. You can see an example of an Urumbu-style controller in Figure 10-2. This chapter won’t cover all that — it’s just going to look at how to build a PCB to control a stepper motor — but you can find out more at hsmag.cc/urumbu. You can also look around the Fab Lab depository, where you can find projects that have used the Urumbu approach, like this excellent pointing machine: hsmag.cc/point.

图 10-2:一台 NEMA 14 电机,其上连接着一块 CNC 加工的基于 SAMD11 的电路板

您需要创建一个单独的 KiCad 项目副本进行后续工作:首先,打开您在第 5 章“设计 RP2040 电路板”中创建的 Minimal RP2040 项目,然后单击“文件”>“另存为”。在您的系统中创建一个新文件夹,并将项目以新名称保存到该文件夹​​中。如果您随后在文件管理应用程序中打开此文件夹,您会发现所有 KiCad 生成的项目文件(SCH 和 PCB 等)都已重命名为新的项目名称。您还可以整理并删除旧项目特有的、与新项目无关的文件。例如,您不会使用 Gerber 文件、CSV 位置文件或 BOM 文件,因为这些文件在新项目中会有所不同。同样,您在 Inkscape 中为 Minimal RP2040 项目创建的边缘切割 SVG 文件也不会被使用,因此您可以将其删除。在开始删除文件之前,请确保您位于正确的项目文件夹中!

You’ll need to create a separate copy of your base KiCad project to work on: first, open the Minimal RP2040 project you created back in Chapter 5, Designing an RP2040 board, and then click File > Save As. Create another folder on your system and save the project into it with a new name. If you then open this folder in a file management application, you will see that all the KiCad-generated project files (the SCH and PCB etc.) have been renamed to the new project name. You can also tidy and delete files which are specific to the old project and not relevant to the new project. For example, you won’t be using the Gerbers, the CSV position, or BOM files, as these will be different for the new project. Similarly, the edge-cut SVG that you created in Inkscape for the Minimal RP2040 project won’t be used, so you can delete it. Make sure that you are in the right project folder before you start deleting files!

由于 Urumbu 步进电机的概念是使用 USB 进行控制,因此 RP2040 是驱动板供电的绝佳选择。

As the concept for Urumbu stepper motors is to use USB for control, RP2040 is a great candidate for powering a driver board.

尺寸增大

Sizing up

Urumbu 社区中已有使用 NEMA 14 电机的案例,这种电机的优点在于通常可以通过 USB 2.0 及以上版本进行控制和供电。然而,大多数小型实验性快速原型机倾向于使用尺寸更大的 NEMA 17 级步进电机。您可以查看任何小型家用或办公用 3D 打印机、小型桌面 CNC 雕刻机或业余绘图仪,都会发现它们使用的是 NEMA 17 电机。

There have been examples in the Urumbu community using NEMA 14 motors, which are convenient in the fact that they can often be controlled and powered by USB 2.0 and above. However, most small experimental rapid prototyping machines tend to use the larger NEMA 17 class of stepper motor. Check out any smaller home- or office-use 3D printer, smaller desktop CNC router, or hobby pen plotter and you’ll find NEMA 17.

以 NEMA 17 为目标,首先需要确定一些机械尺寸并做出一些基本决策。查看 NEMA 17 的数据手册,你会发现封装的外部尺寸为 42 x 42 毫米,并且在 31 毫米见方的四个角上各有一个 M3 螺栓。由于本项目将以最小的 RP2040 电路示例为基础,因此一个好的起点是绘制 NEMA 17 封装图,并将其添加到最小的 RP2040 设计中,以查看其布局效果图 10-3)。

With NEMA 17 as the target, the first port of call is to find some mechanical dimensions and make some fundamental decisions. Looking at datasheets for NEMA 17, you’ll find that the outer dimensions of the package are 42 by 42mm, and that they have a set of M3 bolts through the assembly in the corners of a 31mm square. Because you’ll use the minimal RP2040 circuit example as the basis of this project, a good starting point is to draw up a NEMA 17 footprint and drop it into the minimal RP2040 design to see how things look (Figure 10-3).

图 10-3:导入到最小 RP2040 示例中的 NEMA 17 外形图

您可以使用 Inkscape 快速绘制 NEMA 17 封装图,然后使用“文件”>“导入”>“图形”将其导入 KiCad 的边缘切割图层。完成此操作后,我们发现需要缩小最小 RP2040 布局中的某些部分尺寸,但缩小幅度并不大,因此您也应该做好相应的准备。您不需要引出所有 GPIO 引脚,这样可以轻松节省空间。电路板上勉强够放一个电机驱动 IC 和外围元件,但最好使用电机驱动模块。这样可以使电路板兼容多种电机驱动器。这意味着您需要在一个轴向上扩展电路板的尺寸。在确定了基本可行性之后,您就可以开始编辑原理图以创建新项目了。

You can draw up a quick NEMA 17 footprint in Inkscape and import it to the edge cuts layer in KiCad using File > Import > Graphics. After we did that, it was obvious that we would have to reduce the size of some aspects of the minimal RP2040 layout, but not unreasonably so you should be prepared to do the same. You won’t need all the GPIO pins broken out, which gives you some easy space-savings. There is just about enough room to also lay a motor driver IC and peripheral components on the board, but you’ll be better off using a module for the motor driver section. This makes the board compatible with a range of motor drivers. This means you need to extend the board dimensions in one axis. With this basic feasibility worked out, you can set about editing the schematic to create the new project.

在原理图编辑器中,删除所有 GPIO 引出接头部分,因为它们不再需要。然后,您可以使用符号编辑器为电机驱动模块创建自定义符号(图 10-4)。创建符号后,使用标签将其连接到 RP2040,以便更清晰地阅读原理图。

In the Schematic Editor, delete all the GPIO breakout header sections as they won’t be needed. You can then use the Symbol Editor to create a custom symbol for the motor driver module (Figure 10-4). With the symbol created, connect it to the RP2040 using labels to keep the general schematic sections easier to read.

图 10-4:用于具有相似外形尺寸的各种步进电机驱动模块的自定义符号

使用 NEMA 17 电机而非 NEMA 14 电机的一个区别在于,虽然在一定范围内可以使用大功率 USB 电源以 5V 电压驱动电机,但您可能更希望使用更高的外部电压。大多数常见的步进电机驱动模块都支持此功能,并配有一个“VM”引脚,可用于连接外部电源。

One difference with running a NEMA 17 rather than a NEMA 14 is that although you could, in a slightly limited fashion, run the motor at 5 V from a beefy USB supply, it’s likely you might want to run it from a larger external voltage. Most of the common stepper driver modules can do this and have a ‘VM’ pin into which you can connect an external supply.

为了保留使用 USB 或 VM 的功能,您需要一个外部电源连接器和一个二极管,以便在使用外部电源时保护系统的 USB 端。KiCad 的一大优点是,它采用独立的原理图符号工作流程(然后您可以为每个符号分配元件封装),这意味着您无需立即确定要使用哪个二极管。您可以简单地放置一个二极管符号,将其连接到原理图中,稍后再考虑封装(图 10-5)。

To retain the ability to use either USB or VM, you’ll need a connector for an external supply and a diode to protect the USB side of the system when the external supply is in use. One of the great things about KiCad is that the workflow of separate schematic symbols (to which you then assign a component footprint) means that you don’t have to work out exactly which diode you are going to use right away. You can simply place a diode symbol, wire it into the schematic, and consider the package later (Figure 10-5).

图 10-5: KiCad 的工作流程通常允许您添加通用元件符号,稍后再考虑使用哪个实际元件。

突破

Breaking out

除了电机驱动器之外,您还需要两个连接到 GPIO 和地线的排针插座,以便连接开关作为限位开关;这样,您就可以为使用这些电机开发的任何机器提供反馈和控制选项。同样,您可以直接将这些添加到原理图中。

In addition to the motor driver, you’ll want two header sockets connected to GPIO and ground in case you want to attach switches to act as limit switches; this gives you feedback and control options for any machines that you might develop with these motors. Again, you can simply add these to the schematic.

原理图基本完成后,就可以开始选择元器件,并检查之前使用过的元器件是否仍然有货。在使用PCBA服务时,这一步可能会非常棘手且耗时。截至撰写本文时,我们很高兴地看到JLCPCB仍有RP2040、Winbond闪存芯片和12MHz晶振的库存。我们也花时间确认了电容和电阻等小型元器件也都有库存。

With the adapted schematic largely complete, you can set about making decisions on component choices and check which previously used components are available. This is where things can get very tricky and time-consuming when using PCBA services. At the time of this writing, we were glad to see that the RP2040, the Winbond flash chip, and the 12MHz crystal were still in stock with JLCPCB. We also took the time to check that the smaller components — the capacitors and resistors — were all also in stock.

当时,我们之前使用的USB接口和3.3V稳压器都已缺货。这两款产品周转率都很高,而且在寻找合适的3.3V稳压器的过程中,我们一度找不到任何封装的、适用于本项目的产品。此外,我们还发现,虽然有些稳压器在产品列表中,但无论是产品信息还是元件数据手册,都无法提供足够的信息来决定是否采用该元件。像稳压器这类元件,LCSC(JLCPCB元件仓库的后端供应商)的库存和产品种类都在不断变化和增加。今天在搜索结果中看似棘手的问题,几天后可能就会出现五六个新的选择。

At the time, the USB socket and the 3V3 voltage regulator we had used previously were no longer in stock. Both are high-turnover items and, at one point in this process, we couldn’t identify any 3V3 voltage regulators in any package that were suitable for this project. We also found some challenges in that there would be a regulator listed, but not enough information available either in the listing or the component's datasheet to actually make a decision on whether to include the part. With items like voltage regulators, LCSC (the company that is the back end of the JLCPCB component warehouse) is continually changing and adding items and stock. What can appear a huge problem one day in your search results can suddenly have half a dozen more options in a couple of days' time.

建立仓库

避免元器件短缺的一种方法是提前预订元器件,以便在项目中使用。这有时被称为虚拟仓库,您可以购买一定数量的元器件库存,并将它们存放起来,直到准备将它们组装到PCB板上。此功能已内置于您的JLCPCB帐户中,登录帐户后,您可以进入“零件管理”页面。在此页面上,您可以使用“我的零件库”查看并添加您的个人零件库。您可以购买基础零件和扩展零件,还可以预订缺货的扩展零件,以便在它们补货后立即购买。

One way to avoid component shortages is to pre-order components to be held ready for use in your project. This is sometimes referred to as a Virtual Warehouse, where you can buy an inventory of component stock and hold them until you are ready to place them onto a PCB assembly. This functionality is already built into your JLCPCB account, and once signed in to your account, you can move to the Parts Manager page. On this page, you can use the My Parts Lib to view and to add to your personal parts library. You can buy both Basic and Extended parts, and you can also pre-order out-of-stock extended parts for when they are hopefully restocked.

从JLCPCB零件仓库订购基础零件有最低订购量要求。不过,基础零件缺货的可能性很小,即使缺货,通常也会有类似的替代零件。但需要注意的是,这些预购零件仅供组装服务使用——您不能像订购其他组件一样,直接订购零件库并邮寄给您。

For Basic parts from the JLCPCB parts warehouse, you have a minimum order requirement. However, Basic parts are much less likely to go out of stock and, if they do, they are likely to have an alternate similar part available. One thing you need to know, though, is that these pre-purchased parts are only for use in assembly services — you can’t suddenly have your library of parts mailed to you as a component order.

如果您正在创建一个项目,并且您认为开发周期会很长,组件库存可能会成为一个问题,那么这可能是一个让您安心的好选择。

If you are creating a project and you think you are going to have a long development time where component stock might be an issue, this can be a great option for your peace of mind.

我们最终找到了所有非库存元件的替代品。替换的 USB 接口需要不同的封装,但我们可以从 EasyEDA 下载封装并导入到 KiCad 中(参见“提前规划:元件和封装”)。图 10-6显示了我们找到的新 USB 连接器;我们通过转换产品页面上的 EasyEDA 示例创建了该封装。

We eventually found replacements for all non-stock components. The replacement USB socket required a different footprint, but we could download the footprint from EasyEDA and import it into KiCad (see “Planning ahead: components and footprints”). Figure 10-6 shows the new USB connector we identified; we created the footprint by converting the EasyEDA example on the product page.

图 10-6:新型 USB 连接器尺寸

新的USB连接器虽然有一些通孔元件,但标签上却标明是SMD(表面贴装)。这让我有些担心,因为PCB组装服务对通孔元件的收费比表面贴装元件高得多,不过最终通过单面表面贴装服务安装时并没有出现问题。

The new USB connector had some through-hole chassis components but was listed as an SMD. This concerned me, as the PCB assembly service charges quite a bit more for through-hole than surface-mount, but the part was attached via the single side surface-mount services without problems.

图 10-7:当试图最大限度地减少重新设计并面临组件变更时,您将花费大量时间使用搜索选项!

由于一度找不到合适的电压调节器,我们不得不暂停这个项目两天。后来,我们在JLCPCB元件库中找到了其他库存,并成功找到了一款可以直接替换的SOT23封装的稳压器。务必仔细核对更换元件的封装和引脚排列,确保线路仍然有效。

Having struggled to identify a suitable voltage regulator in any package at one point, we left the project for a couple of days. Later, we found different stock available in the JLCPCB parts library and managed to find a drop-in replacement regulator which would sit on the same SOT23 footprint. It’s definitely worth triple-checking the footprint and pinout of any swapped components to ensure that your wiring still works.

大部分元件问题都已解决,接下来就可以开始编辑PCB布局了。你需要让最小的RP2040布局更加紧凑,以适应NEMA 17封装尺寸,因此应该将RP2040芯片和晶振向上移动,缩短它们与USB接口之间的距离。有时,在重新设计PCB时,抓取功能非常实用。你可以选择一条走线,或者选择一组走线和元件,然后使用G快捷键而不是M键。这样,它不会简单地移动元件,而是会抓取元件,并且走线的连接性保持不变,你可以移动这些元件。根据我们的经验,这种方法很少能得到整齐的走线,但它可以快速创建一个新的布线方案,然后你可以手动编辑它。

With most of the problems solved with regards to components, you can set about editing the PCB layout. You’ll need to make the minimal RP2040 layout more compact to fit within the NEMA 17 footprint, and so you should move the actual RP2040 and crystal upwards, decreasing the distance between it and the USB socket. Sometimes, in reworking a PCB like this, the grab function is quite handy, where you can select a track, or a selection of tracks and components, and then use the G hot key rather than M and, instead of simply moving the objects, they are grabbed and the track connectivity remains which the tracks can move. This rarely results in a neat set of tracks in our experience, but it can be useful to create a quick new routing which you can then manually edit.

图 10-8: Urumbu RP2040 PCB 完整布局图

PCB设计完成后,下一步是创建项目的Gerber文件、BOM文件和位置文件,并将其上传到JLCPCB。PCB组装完成后,经过短暂的生产和交付,我们使用FreeCAD设计了一个用于3D打印的支架,然后只需使用一些较长的M3螺栓即可将电路板固定到NEMA 17插座上。如果您有兴趣复制这些电路板或尝试RP2040 Urumbu风格的设计,请从书籍库hsmag.cc/kicad_book_files下载此项目。

With the PCB design complete, the next step is to create the Gerbers, BOM, and positional files for the project and upload it to JLCPCB. After a short production and delivery of the assembled PCBs, we created a standoff design for 3D printing using FreeCAD, and then the boards simply attach to a NEMA 17 using some longer M3 bolts. If you are interested in replicating these boards or playing with RP2040 Urumbu-style approaches, download this project from the book repository hsmag.cc/kicad_book_files.

哎呀呀

秉持着坦诚面对失败的精神,我想分享一下我在制作这块PCB时犯的一个错误。使用电机驱动模块而不是围绕特定的电机驱动IC进行设计,意味着即使某些电机驱动器缺货,我也拥有很大的灵活性和冗余度。像TMC2208模块、DRV8833模块和A4988模块这样的电机驱动板都采用相同的封装,共有16个引脚,分为两排,每排8个引脚,引脚间距为2.54mm。

In the spirit of failing out loud, I’d like to share a mistake I made in the production of this PCB. Using motor driver modules rather than designing around a particular motor driver IC meant I had lots of flexibility and redundancy even if certain motor drivers were out of stock. The motor driver boards like the TMC2208 module, the DRV8833 module, and the A4988 module all share a common footprint with 16 pins, in two rows of eight pins in 2.54mm spacing.

我不知道各行之间的间距,但我朋友桌上正好有一个模块,我就向他询问了尺寸。他发给我几张照片,照片里有他用卡尺测量电路板尺寸的示意图,还有他把模块放在面包板上的示意图。我迅速数了一下面包板上的间距,看看模块有多少列宽。引脚行的宽度是六列。

I didn’t know the spacing between the rows, but a friend had a module on their desk and I messaged them for some dimensions. They sent me a collection of pictures with callipers held to the board, and the module placed into a breadboard. I quickly counted across the breadboard to see how many columns wide the module was. It’s six columns wide across the pin rows.

在设计模块的简单封装时,我在封装编辑器中将网格设置为 2.54 毫米,然后绘制了一列八个引脚。接着,我横向数了六行,绘制了第二列。当然,这是个错误:横向数六行会导致模块跨越面包板的七列,因此宽度多了 2.54 毫米。最简单的事情往往最糟糕!

When laying out the simple footprint for the module, I set the grid to 2.54mm in the footprint editor and then drew one column of eight pins. I then counted across six rows and laid out the second column. Of course, that is an error: counting six rows across makes a module that would span seven columns of a breadboard and is therefore 2.54mm too wide. The simplest things are often the worst!

这类错误的难点在于,DRC系统无法检测到它们,因为对于这种简单的封装来说,连接看起来是正确的。直到组装好的PCB板到货后,我才意识到这个错误。由于我生产的电路板数量不多,我只能采取一种糟糕的临时解决方案:稍微倾斜一下排针插座,使其接近正确位置,然后再插入模块。虽然方法粗糙,但至少能让我使用这些电路板。人都会犯错;如果你也犯了错,不要太自责。

The challenge with this sort of error is that they are not the kind of errors that can be detected by the DRC system, as connectivity to this simple footprint looks correct to the system. Only when the assembled PCBs arrived did I realise the error. For the small number of boards I had manufactured, the horrid workaround is to slightly angle in the header sockets to bring them close to correct and then insert the module. Crude, but allows me to use the boards. Everyone will make mistakes; if and when it happens to you, don’t beat yourself up too much.

——乔

— Jo

第十一章

Chapter 11

制作RP2040游戏控制器

Making an RP2040 game controller

让我们来探讨如何调整RP2040的布局,使其成为一个USB游戏控制器。

Let’s explore adapting the RP2040 layout to make a USB game controller

前面的章节已经建立了一个合理的RP2040布局,因此现在创建新的RP2040器件非常简单。上一章用它制作了一个Urumbu风格的电机驱动板,而本章将介绍如何制作一个简单的USB游戏控制器(图11-1)。

Earlier chapters established a reasonable working RP2040 layout, so now it’s trivial to create new RP2040 devices. The last chapter used it to make an Urumbu-style motor driver board, and in this chapter, you’ll see how you can create a simple USB game controller (Figure 11-1).

图 11-1:完成的游戏控制器 PCB

这与你之前处理 Urumbu 项目的过程基本相同。首先,复制 Urumbu 项目,然后清理新副本中不需要的文件:电路板边缘几何图形、Gerber 文件和 CSV 文件都可以删除,因为你将用新项目生成的文件替换它们。你还可以删除原理图中所有不需要的 Urumbu 元件。你实际上不需要在 PCB 编辑器中删除元件,因为当你最终导入更新后的网络表和物料清单时,系统会自动删除未引用的封装,并导入新的封装。

It’s largely the same process you undertook for the Urumbu project. Start by making a copy of the Urumbu project and clean out any files in the new project copy that you don’t need: the board edge geometry, the Gerbers, and CSV files can all be deleted, as you will replace them with ones generated for the new project. You can also delete all the Urumbu parts on the schematic that you don’t need. You don’t really need to delete items in the PCB Editor, as when you eventually pull in the updated netlist and bill of materials, you can automatically delete unreferenced footprints, and the new footprints will be brought in.

你需要为RP2040添加六个触觉按钮:四个组成方向键,另外两个分别作为A键和B键。这些按钮需要是瞬时按下按钮(也称为“按一下接通”按钮)。每个按钮的一端连接到GPIO引脚,另一端接地。

You’ll need to add six tactile buttons to the RP2040: four in a D-pad arrangement and two as A- and B-style buttons. You will want these buttons to be momentary press buttons (also known as push to make). You’ll connect one side of each button to a GPIO and the other side to ground.

我们在 JLCPCB 元件库中找到了 C221902 按钮。这款元件尺寸合适,于是我们查看了 EasyEDA 的原理图和封装。它有四个引脚,根据原理图,我们可以将引脚 2 连接到 GPIO,并将其他引脚接地,这样就能正常工作。此外,它采用四个 SMD 焊盘,机械强度应该不错。

Scouring the JLCPCB parts library, we came across the C221902 button. This part looked a nice size, so we looked at the EasyEDA schematic and footprint. It has four pins and, reading the schematic, we could see that if we connected pin 2 to a GPIO and then connected all the other pins to ground, it would work as needed. Additionally, with the four SMD pads, it should be mechanically strong.

高性能

本章探讨如何打造一款易于理解和扩展的游戏手柄。然而,如果您想打造一款高性能的游戏手柄,则需要考虑诸多因素。元件布局显然是其中至关重要的一环,因为您需要能够稳定、精准地按下按键。

This chapter looks at creating a gamepad that’s easy to understand and extend. However, if you’re looking to build a high-performance gamepad, then there are lots of things that you need to consider. Part placement is obviously a large part of it, as you need to be able to press buttons consistently and accurately.

然而,软件也是需要考虑的因素。CircuitPython 的代码虽然还有改进的空间,但最终,如果你追求的是高性能,CircuitPython 并非最佳选择。幸运的是,还有其他选择。

However, another part is the software. The CircuitPython code could be improved, but ultimately, if you’re looking for high performance, CircuitPython isn’t the right choice. Fortunately, there is another option.

GP2040-CE 是一款适用于基于 RP2040 设备的固件。您可以配置固件,详细说明各个硬件的连接位置。它不仅支持按钮输入,还支持模拟输入。

GP2040-CE is a firmware for RP2040-based devices. You can configure it with details of what hardware is connected where. It understands more than just buttons, so you can add analogue inputs as well.

项目网站上有相关文档:hsmag.cc/GP2040-CE

There’s documentation on the project website: hsmag.cc/GP2040-CE.

选定元件后,我们从 EasyEDA 下载了封装图,并将其导入 KiCad(参见“提前规划:元件和封装图”),然后将其添加到自定义库中。

With the choice of parts made, we downloaded the footprint from EasyEDA and imported it into KiCad (see “Planning ahead: components and footprints”), then add it to a custom library.

要将按钮添加到原理图中,您可以创建一个自定义的 4 引脚原理图符号,并将其插入到分层图纸中。接下来,将 GPIO 引脚和其他引脚接地,然后引出 GPIO 分层引脚。然后,复制该分层图纸,创建六个版本,每个版本对应一个按钮,并在添加每个按钮时调整标签和图纸名称(图 11-2)。

To add the buttons to the schematic, you can create a custom 4-pin schematic symbol and insert it into a hierarchical sheet. Next, wire the GPIO pin and the other pins to ground and then bring out the GPIO hierarchical pin. Then, copy the hierarchical sheet to create six versions, one for each button, adjusting the label and the sheet name as you add each (Figure 11-2).

图 11-2:使用分层图纸可以轻松添加多个相似的连接原理图模块,例如按钮

接下来,将新的封装分配给原理图符号,并开始编辑PCB布局。在执行JLCPCB服务所需的常规Gerber文件、BOM文件和位置文件导出之前,您应该在Inkscape中创建一个新的板边几何SVG文件,其中包含一些安装孔( “雕刻路径” )(图11-3)。

Next, assign the new footprints to the schematic symbols and began to edit the PCB layout. You should create and import a new board edge geometry SVG in Inkscape with some mount holes (“Carving a path”) before carrying out the usual exporting of Gerbers, BOM, and positional files for JLCPCB services (Figure 11-3).

图 11-3:完成的 PCB 布局

订购电路板之后,硬件方面最后一个有趣的步骤是从 KiCad 导出 STEP 文件,以便在 FreeCAD 中建模。要从 KiCad PCB 编辑器导出基本的 STEP 文件,请选择“文件”>“导出”,然后选择 STEP 作为输出格式。请注意,您尚未为所有自定义组件添加自定义 3D 模型,因此 STEP 文件显然并不完全准确,但它足以作为在 FreeCAD 中建模的参考。

After ordering the boards, one final fun activity on the hardware side of this build is to export a STEP file from KiCad to model around in FreeCAD. To export a basic STEP file from the KiCad PCB Editor, select File > Export and then choose STEP as the output format. Note that you haven’t added custom 3D models for all the custom components, so obviously the STEP file isn’t completely correct, but it serves as a good enough guide to model around in FreeCAD.

在免费下载的《FreeCAD For Makers》(hsmag.cc/freecadbook)一书中,我们探讨了如何使用FreeCAD和KiCad StepUp工作台,该工作台允许您创建和定位自定义3D组件模型,以便在KiCad中使用。我们还探讨了创建各种模型所需的所有技能。凭借本书所学的知识,您完全可以制作出像我们快速建模的控制器外壳(图11-4)。

In the free-to-download book FreeCAD For Makers (hsmag.cc/freecadbook), we explored using FreeCAD and the KiCad StepUp workbench that allows you to create and position custom 3D component models for use in KiCad. we also explored all the skills needed to create all kinds of models. With the knowledge you gain from this book, you could certainly make a controller enclosure like the one we quickly modelled (Figure 11-4).

图 11-4:在 FreeCAD 中建模一个简单的外壳,使控制器握持起来更舒适。
其他游戏手柄

这个例子应该能让你入门游戏控制器的世界,你还可以参考很多其他例子来获得灵感:

This example should get you started in the world of game controllers, and there are loads that you can look at for inspiration:

  • Arduino Esplora 现已停产,但它是市面上最早一批可破解的游戏控制器之一:hsmag.cc/ArduinoEsplora
  • The Arduino Esplora is now retired, but was one of the first hackable game controllers on the market: hsmag.cc/ArduinoEsplora
  • PCBWay 的共享项目网站上有一个在线社区,其中包含许多游戏控制器,例如:hsmag.cc/PicoGamepad
  • There’s an online community at PCBWay’s shared projects site that includes many game controllers, including: hsmag.cc/PicoGamepad
  • 游戏手柄的形状多种多样。它们的设计通常以人体工程学为核心,但你也可以发挥一些创意。例如,这位开发者就打造了一款蝙蝠形状的手柄:hsmag.cc/BatController
  • Gamepads come in many shapes. They’re usually designed around ergonomics, but you can get a little creative. For example, this maker has built a bat-shaped controller: hsmag.cc/BatController

柔和的一面

The softer side

现在电路板已经制作完成,是时候为其编写代码了。您可以使用 Pico SDK 以 C 语言编写代码。您也可以使用 Pico 版本的 MicroPython 或 CircuitPython。但是,由于您创建的是一块新电路板,因此最好为其专门定制固件——即自定义版本的 CircuitPython。这样做的好处有两点:首先,您可以为特定引脚命名,例如,您可以将 GPIO0 替换为 BTN_A;其次,您可以选择要包含的模块。在本项目中,您将添加 Adafruit HID 模块,以便将游戏控制器用作输入设备。

Now that you have created the board, it’s time to write some code for it. You could write the code in C using the Pico SDK. You could also use the Pico build of MicroPython or CircuitPython. However, since you’ve created a new board, it’s helpful to create a firmware tailored specifically for it — a custom build of CircuitPython. This allows you to do a couple of things. Firstly, it lets you name the specific pins, so rather than using, say, GPIO0, you can use BTN_A. Secondly, it lets you select which modules we want to include. In the case of this project, you’ll add Adafruit HID, which enables you to use the game controller as an input device.

我们发现使用适用于 Linux 的 Windows 子系统 (WSL) 构建 CircuitPython 最为简便(图 11-5),但构建 CircuitPython 的一般流程在hsmag.cc/BuildCP 的文档中有所介绍。我们在此不再赘述,请按照该指南设置您的环境。

We found it easiest to build CircuitPython using Windows Subsystem for Linux (Figure 11-5), but the general process for creating a build of CircuitPython is given in the documentation at hsmag.cc/BuildCP. We won’t go through it in detail, so follow that guide to set up your environment.

图 11-5:使用 Windows 子系统 Linux 构建 CircuitPython
无铅

使用含铅焊料制作电路板通常更便宜。然而,这可能是一种得不偿失的做法。含铅焊料对您的健康和地球环境都有害。对于游戏手柄这种需要反复握持的设备来说,选择无铅焊料尤为重要。即使每次使用时只有少量焊料沾到手上,在手柄的使用寿命内,这些焊料也会累积起来,并可能对您的健康造成负面影响。

It’s often cheaper to get boards made using leaded solder. However, this might be a false economy. Leaded solder is harmful to both your health and the health of our planet. In the case of a games controller — something that you’re going to hold in your hand time and again — it’s more important than usual to opt for lead-free solder. Even if only a tiny amount gets on your hands each time you use it, that will still add up over the course of the controller’s life and could have negative effects on your health.

一切准备就绪后,你需要创建这个开发板。在circuitpython/ports/raspberrypi/boards目录下,将raspberry_pi_pico目录复制到一个新目录中,新目录的名称要与游戏手柄的名称相符。我们将其命名为hackspace_gamepad

Once you have everything set up, you need to create this board. In the directory circuitpython/ports/raspberrypi/boards, copy the raspberry_pi_pico directory into a new one named appropriately for the gamepad. We called ours hackspace_gamepad.

要为您的开发板定制 CircuitPython,您需要修改两个文件。首先是pins.c 文件,您应该将其编辑为如下所示,这将向 boards 模块添加条目(每个按钮一个条目):

There are two files that you need to adjust to customise CircuitPython for your board. Firstly, there’s pins.c, which you should edit to read as follows, which adds items to the boards module (one item for each button):

#include "shared-bindings/board/__init__.h"
#include "shared-bindings/board/__init__.h"
STATIC const mp_rom_map_elem_t board_module_globals_table[] = {
STATIC const mp_rom_map_elem_t board_module_globals_table[] = {
    CIRCUITPYTHON_BOARD_DICT_STANDARD_ITEMS
    CIRCUITPYTHON_BOARD_DICT_STANDARD_ITEMS
    { MP_ROM_QSTR(MP_QSTR_UP), MP_ROM_PTR(&pin_GPIO0) },
    { MP_ROM_QSTR(MP_QSTR_UP), MP_ROM_PTR(&pin_GPIO0) },
    { MP_ROM_QSTR(MP_QSTR_RIGHT), MP_ROM_PTR(&pin_GPIO1) },
    { MP_ROM_QSTR(MP_QSTR_RIGHT), MP_ROM_PTR(&pin_GPIO1) },
    { MP_ROM_QSTR(MP_QSTR_LEFT), MP_ROM_PTR(&pin_GPIO2) },
    { MP_ROM_QSTR(MP_QSTR_LEFT), MP_ROM_PTR(&pin_GPIO2) },
    { MP_ROM_QSTR(MP_QSTR_DOWN), MP_ROM_PTR(&pin_GPIO3) },
    { MP_ROM_QSTR(MP_QSTR_DOWN), MP_ROM_PTR(&pin_GPIO3) },
    { MP_ROM_QSTR(MP_QSTR_BTN_A), MP_ROM_PTR(&pin_GPIO18) },
    { MP_ROM_QSTR(MP_QSTR_BTN_A), MP_ROM_PTR(&pin_GPIO18) },
    { MP_ROM_QSTR(MP_QSTR_BTN_B), MP_ROM_PTR(&pin_GPIO19) }
    { MP_ROM_QSTR(MP_QSTR_BTN_B), MP_ROM_PTR(&pin_GPIO19) }
};
};
MP_DEFINE_CONST_DICT(board_module_globals, 
MP_DEFINE_CONST_DICT(board_module_globals, 
                     board_module_globals_table);
                     board_module_globals_table);

接下来,将mpconfigboard.mk文件编辑为以下内容:

Next, edit mpconfigboard.mk to be the following:

USB_VID =0x1209
USB_VID = 0x1209
USB_PID =0xB182
USB_PID = 0xB182
USB_PRODUCT = "HackSpace gamepad"
USB_PRODUCT = "HackSpace gamepad"
USB_MANUFACTURER = "HackSpace magazine"
USB_MANUFACTURER = "HackSpace magazine"
CHIP_VARIANT =RP2040
CHIP_VARIANT = RP2040
CHIP_FAMILY =rp2
CHIP_FAMILY = rp2
EXTERNAL_FLASH_DEVICES = "W25Q128JVxQ"
EXTERNAL_FLASH_DEVICES = "W25Q128JVxQ"


CIRCUITPY__EVE = 1
CIRCUITPY__EVE = 1
FROZEN_MPY_DIRS += $(顶部)/frozen/Adafruit_CircuitPython_HID
FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_HID

mpconfigboard.mk 文件中,您可以定义闪存芯片的类型,并添加所需的“冻结”模块。冻结模块可以是您希望默认包含在构建过​​程中的任何模块(除了自动包含的核心模块)。冻结模块必须位于circuitpython/frozen目录中,但您应该会发现该Adafruit_CircuitPython_HID模块已经存在于此目录中。

In mpconfigboard.mk, you define the type of flash chip you have and add any ‘frozen’ modules you want. Frozen modules can be anything that you want to be included on the build by default (other than the core modules that are automatically included). Frozen modules must be in the circuitpython/frozen directory, but you should find that the Adafruit_CircuitPython_HID module is already there.

现在,您可以通过访问circuitpython/ports/raspberrypi并运行以下命令来创建您的构建:

You can now create your build by going to circuitpython/ports/raspberrypi and running:

制作 BOARD=hackspace_gamepad
make BOARD=hackspace_gamepad

这将编译你的代码,最终会生成一个名为build-hackspace_gamepad 的目录。在这个目录中,你会找到一个名为firmware.uf2 的文件,你可以像加载其他 UF2 文件一样将其加载到你的游戏手柄上。

This will compile your code, and you should end up with a build-hackspace_gamepad directory. In there, you’ll find a firmware.uf2 file that you can load onto your gamepad just as you would any other UF2 file.

这并非完整的固件——它只是编程语言。现在你需要编写一个程序才能让所有功能正常工作。幸运的是,所有需要的模块都已内置,因此无需安装任何其他模块。以下固件示例借鉴了 CircuitPython 示例代码。将其保存为code.py到设备文件系统的根目录:

This isn’t complete firmware — it’s only the programming language. You now need to write a program to get everything working. Fortunately, you have all the modules we need baked in, so there’s no need to install any additional modules. Here’s some firmware that draws inspiration from the CircuitPython example code. Save it as code.py into the root of the device’s filesystem:

import time
import time
import board
import board
import digitalio
import digitalio
import usb_hid
import usb_hid
from adafruit_hid.keyboard import Keyboard
from adafruit_hid.keyboard import Keyboard
from adafruit_hid.keyboard_layout_us import KeyboardLayoutUS
from adafruit_hid.keyboard_layout_us import KeyboardLayoutUS
from adafruit_hid.keycode import Keycode
from adafruit_hid.keycode import Keycode


# A simple neat keyboard demo in CircuitPython
# A simple neat keyboard demo in CircuitPython


# The pins we'll use, each will have an internal pullup
# The pins we'll use, each will have an internal pullup
keypress_pins = [board.UP, board.DOWN, board.LEFT, 
keypress_pins = [board.UP, board.DOWN, board.LEFT, 
                 board.RIGHT, board.BTN_A, board.BTN_B]
                 board.RIGHT, board.BTN_A, board.BTN_B]
# Our array of key objects
# Our array of key objects
key_pin_array = []
key_pin_array = []
# Keycode sent for each button, will be paired with a control key
# Keycode sent for each button, will be paired with a control key
keys_pressed = [Keycode.UP_ARROW, Keycode.DOWN_ARROW,
keys_pressed = [Keycode.UP_ARROW, Keycode.DOWN_ARROW,
                Keycode.LEFT_ARROW, Keycode.RIGHT_ARROW,
                Keycode.LEFT_ARROW, Keycode.RIGHT_ARROW,
                Keycode.A, Keycode.B]
                Keycode.A, Keycode.B]


# Sleep to avoid a race condition on some systems
# Sleep to avoid a race condition on some systems
time.sleep(1)  
time.sleep(1)  


keyboard = Keyboard(usb_hid.devices)
keyboard = Keyboard(usb_hid.devices)
keyboard_layout = KeyboardLayoutUS(keyboard)  
keyboard_layout = KeyboardLayoutUS(keyboard)  


# Make all pin objects inputs with pullups
# Make all pin objects inputs with pullups
for pin in keypress_pins:
for pin in keypress_pins:
    key_pin = digitalio.DigitalInOut(pin)
    key_pin = digitalio.DigitalInOut(pin)
    key_pin.direction = digitalio.Direction.INPUT
    key_pin.direction = digitalio.Direction.INPUT
    key_pin.pull = digitalio.Pull.UP
    key_pin.pull = digitalio.Pull.UP
    key_pin_array.append(key_pin)
    key_pin_array.append(key_pin)


print("Waiting for key pin...")
print("Waiting for key pin...")


while True:
while True:
    # Check each pin
    # Check each pin
    for key_pin in key_pin_array:
    for key_pin in key_pin_array:
        i = key_pin_array.index(key_pin)
        i = key_pin_array.index(key_pin)
        key = keys_pressed[i]
        key = keys_pressed[i]
        if not key_pin.value:  # Is it grounded?
        if not key_pin.value:  # Is it grounded?
            print("Pin #%d is grounded." % i)
            print("Pin #%d is grounded." % i)
            # "Type" the Keycode or string
            # "Type" the Keycode or string
            keyboard.press(key)  # "Press"...
            keyboard.press(key)  # "Press"...
        else:
        else:
            keyboard.release(key)
            keyboard.release(key)
    time.sleep(0.01)
    time.sleep(0.01)

如您所见,您可以在代码中使用`board.UP``board.DOWN``board.LEFT``board.RIGHT``board.BTN_A``board.BTN_B`。这有两个优点。首先,它对程序员来说更直观。其次,如果您创建了另一个版本的电路板,按钮位于不同的引脚上,相同的代码仍然可以在两个版本上运行。

As you can see, you can use board.UP, board.DOWN, board.LEFT, board.RIGHT, board.BTN_A, and board.BTN_B in your code. This has a couple of advantages. Firstly, it is more intuitive for programmers. Secondly, if you created another version of the board with the buttons on different pins, the same code could still run on both.

图 11-6:自定义构建的 CircuitPython 包含了我们所需的一切,包括引脚名称和模块。

这段代码有点偷懒。例如,按钮没有做防抖处理time.sleep(0.01)。实际上,我们发现这不会造成太多问题,尤其是在某些特定情况下。这意味着它的响应速度不是最快的,所以如果你玩的游戏对响应时间要求很高,比如百分之一秒,你可能需要使用其他方法,例如用 C 语言编写的经过优化的防抖处理。不过,这个控制器本身也不适合这类游戏。此外,它发送的报告数量也相当随意(报告是指从键盘发送到计算机的状态更新)。每次循环会发送六个报告,这意味着每秒发送数百个报告。同样,这不利于性能。但是,它运行稳定可靠,而且易于理解。

This code is a bit lazy. For example, there’s no debouncing on the buttons. In practice, we’ve found that this doesn’t cause many problems, especially with the time.sleep(0.01) in there. This means it’s not the most responsive controller, so if you’re playing games where hundredths of a second matter, you probably want to use something different, such as tuned debouncing written in C. However, this controller isn’t suitable for that type of game anyway. This is also fairly cavalier with the number of reports it sends (a report being a status update sent from keyboard to computer). This will send six of them every loop, which means several hundred a second. Again, this isn’t great for performance. However, it works reliably and is easy to understand.

加载这段代码后,你应该可以将控制器插入任何电脑,电脑都会将其识别为 USB 键盘。按下其中一个按钮,电脑应该会像识别普通键盘一样识别该按键操作。这样,你就可以控制任何需要电脑输入的游戏了。

With this code loaded, you should be able to plug the controller into any computer and it will recognise it as a USB keyboard. Press one of the buttons and the computer should recognise that button press just as it would from any keyboard. With this, you can control any game that takes input from a computer.

创建自定义版本的 CircuitPython 在构建新电路板时并非必要;但是,一旦你经历过这个过程,它就很容易,而且会让你的生活更美好,尤其是在你将电路板分发给其他人时。

Creating a custom version of CircuitPython isn’t essential when you build a new board; however, once you’ve been through the process once, it’s easy, and makes life a little bit nicer, especially if you’re distributing the board to other people.

至此,我们关于 RP2040 的 KiCAD 之旅就结束了。PCB 设计是一个引人入胜且内容丰富的领域,但现在你应该已经掌握了足够的知识来设计与 Raspberry Pi Pico 兼容的电路板,并将其交给 PCB 组装公司进行生产。你应该理解最小设计,并能够根据自身需求进行调整。你可以添加更多硬件,也可以将其精简到最小尺寸。你可以将 PCB 设计成适合项目的特定形状,甚至可以将 PCB 集成到整个结构中。

This concludes our tour of KiCAD with RP2040. PCB design is a fascinating and huge subject, but you should now know enough to design Raspberry Pi Pico-compatible boards, and get them made by a PCB assembly company. You should understand the minimal design and be able to tweak it to your needs. You can add more hardware, or strip it back to its smallest size. You can make the PCB a specific shape to fit in your project, or even make the PCB an integral part of the structure.

覆盖